Class: Kaizen::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/kaizen/cli.rb

Constant Summary collapse

"Small improvements, every day.\nThe compound interest of discipline."

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(argv) ⇒ Object



11
12
13
# File 'lib/kaizen/cli.rb', line 11

def self.start(argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kaizen/cli.rb', line 15

def run(argv)
  command = argv.shift

  if command.nil? || %w[-h --help].include?(command)
    puts help
    exit 0
  end

  case command
  when '-v', '--version'
    puts "kaizen #{Kaizen::VERSION}"
    exit 0
  when 'done'
    handle_done(argv)
  when 'undo'
    handle_undo
  when 'today'
    handle_today
  when 'yesterday'
    handle_yesterday
  when 'week'
    handle_week
  when 'month'
    handle_month
  when 'log'
    handle_log(argv)
  when 'streak'
    handle_streak
  when 'stats'
    handle_stats
  else
    warn "Unknown command: '#{command}'"
    puts help
    exit 1
  end
rescue StandardError => e
  warn "Error: #{e.message}"
  exit 1
end