Class: Rosette::Client::Cli

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(terminal, writer, api, repo) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
16
# File 'lib/rosette/client/cli.rb', line 11

def initialize(terminal, writer, api, repo)
  @api = api
  @terminal = terminal
  @writer = writer
  @repo = repo
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



9
10
11
# File 'lib/rosette/client/cli.rb', line 9

def api
  @api
end

#repoObject (readonly)

Returns the value of attribute repo.



9
10
11
# File 'lib/rosette/client/cli.rb', line 9

def repo
  @repo
end

#terminalObject (readonly)

Returns the value of attribute terminal.



9
10
11
# File 'lib/rosette/client/cli.rb', line 9

def terminal
  @terminal
end

#writerObject (readonly)

Returns the value of attribute writer.



9
10
11
# File 'lib/rosette/client/cli.rb', line 9

def writer
  @writer
end

Instance Method Details

#start(argv) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rosette/client/cli.rb', line 18

def start(argv)
  if command_const = find_command_const(argv.first)
    command_const.new(api, terminal, writer, repo, argv[1..-1]).execute
  else
    terminal.say("Command '#{argv.first}' not recognized.")
  end
rescue Rosette::Client::ApiError => e
  terminal.say("An api error occurred: #{e.message}")
end