Class: Exercism::Rb::CLI

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

Constant Summary collapse

COMMANDS =
%w[new edit test irb submit use current path list clear help version].freeze
COMMAND_METHODS =
{
  "new" => :new_command,
  "edit" => :edit_command,
  "test" => :test_command,
  "irb" => :irb_command,
  "submit" => :submit_command,
  "use" => :use_command,
  "current" => :current_command,
  "path" => :path_command,
  "list" => :list_command,
  "clear" => :clear_command,
  "help" => :help_command,
  "-h" => :help_command,
  "--help" => :help_command,
  "version" => :version_command,
  "-v" => :version_command,
  "--version" => :version_command
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out: $stdout, err: $stderr) ⇒ CLI

Returns a new instance of CLI.



32
33
34
35
36
37
38
39
40
# File 'lib/exercism/rb/cli.rb', line 32

def initialize(argv, out: $stdout, err: $stderr)
  @argv = argv.dup
  @ui = UI.new(out: out, err: err)
  @state = State.new
  @runner = CommandRunner.new(ui: @ui)
  @track = Config.track
  @root = Config.root(@track)
  @resolver = Resolver.new(state: @state, track: @track, root: @root)
end

Class Method Details

.start(argv, out: $stdout, err: $stderr) ⇒ Object



28
29
30
# File 'lib/exercism/rb/cli.rb', line 28

def self.start(argv, out: $stdout, err: $stderr)
  new(argv, out: out, err: err).start
end

Instance Method Details

#startObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/exercism/rb/cli.rb', line 42

def start
  command = @argv.shift || "help"
  handler = COMMAND_METHODS.fetch(command) { raise Error, "Unknown command: #{command}. Use `xrb help`." }

  __send__(handler)

  0
rescue Error => error
  @ui.error(error.message)
  1
rescue Interrupt
  @ui.error("Interrupted.")
  130
end