Class: Lexdrill::CLI

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

Constant Summary collapse

COMMANDS =
{
  print_version: %w[version --version -v],
  print_help: %w[help --help -h],
  run_next: %w[next],
  run_hook: %w[hook],
  run_start: %w[start],
  run_stop: %w[stop],
  run_inspect: %w[inspect]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



18
19
20
# File 'lib/lexdrill/cli.rb', line 18

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



22
23
24
# File 'lib/lexdrill/cli.rb', line 22

def argv
  @argv
end

Class Method Details

.start(argv = ARGV) ⇒ Object



14
15
16
# File 'lib/lexdrill/cli.rb', line 14

def self.start(argv = ARGV)
  new(argv).start
end

Instance Method Details

#startObject



24
25
26
27
28
29
30
# File 'lib/lexdrill/cli.rb', line 24

def start
  command = argv.first || "help"
  handler = COMMANDS.find { |_method, options| options.include?(command) }&.first
  return print_unknown_command(command) unless handler

  send(handler)
end