Class: Idonethis::Adapters::Cli

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

Class Method Summary collapse

Class Method Details

.run(argv = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/adapters/cli.rb', line 10

def run(argv={})
  args = parse(argv)

  command,*rest = argv
  
  args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
  credential = Settings.credential 

  log.call "args: #{args}, command: #{command}, rest: #{rest}"
  
  use_cases = {
    list:   Idonethis::UseCases::List.method(:apply),
    new:    Idonethis::UseCases::New.method(:apply),
    config: Idonethis::UseCases::Config.method(:apply),
    help:   ->(credential, args) { puts "TODO: implement help" }
  }

  use_case = use_cases[command.to_sym]

  unless use_case
    puts "No command <#{command.to_sym}> found"
    return
  end

  use_case.call credential, args
end