Class: IchigoIchie::CLI

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

Constant Summary collapse

'One day. One encounter. It will not come again.'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(argv) ⇒ Object



12
13
14
# File 'lib/ichigo_ichie/cli.rb', line 12

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

Instance Method Details

#run(argv) ⇒ Object



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
54
55
56
# File 'lib/ichigo_ichie/cli.rb', line 16

def run(argv)
  command = argv.shift

  # Default: show today's quote
  if command.nil?
    handle_today
    return
  end

  case command
  when '-h', '--help'
    puts help
    exit 0
  when '-v', '--version'
    puts "ichigo #{IchigoIchie::VERSION}"
    exit 0
  when 'today'
    handle_today
  when 'tomorrow'
    handle_tomorrow
  when 'date'
    handle_date(argv)
  when 'add'
    handle_add(argv)
  when 'list'
    handle_list
  when 'remove'
    handle_remove(argv)
  when 'count'
    handle_count
  when 'setup'
    handle_setup
  else
    warn "Unknown command: '#{command}'"
    puts help
    exit 1
  end
rescue StandardError => e
  warn "Error: #{e.message}"
  exit 1
end