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],
  run_beat: %w[beat],
  run_beat_alias: %w[polka waltz rock jazz jiga balkan samba],
  run_format: %w[format],
  run_add: %w[add],
  run_list: %w[list],
  run_open: %w[open],
  run_stats: %w[stats],
  run_rand: %w[rand],
  run_go: %w[go],
  run_remote: %w[remote],
  run_oauth: %w[oauth],
  run_sheet: %w[sheet],
  run_export: %w[export],
  run_import: %w[import]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



32
33
34
# File 'lib/lexdrill/cli.rb', line 32

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



36
37
38
# File 'lib/lexdrill/cli.rb', line 36

def argv
  @argv
end

Class Method Details

.start(argv = ARGV) ⇒ Object



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

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

Instance Method Details

#startObject



38
39
40
41
42
43
44
# File 'lib/lexdrill/cli.rb', line 38

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