Class: Lexdrill::CLI

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

Overview

Subcommand dispatcher for the lexdrill executable.

Constant Summary collapse

COMMANDS =
{
  print_version: %w[version --version -v],
  print_help: %w[help --help -h]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



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

def initialize(argv)
  @argv = argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



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

def argv
  @argv
end

Class Method Details

.start(argv = ARGV) ⇒ Object



10
11
12
# File 'lib/lexdrill/cli.rb', line 10

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

Instance Method Details

#startObject



20
21
22
23
24
25
26
# File 'lib/lexdrill/cli.rb', line 20

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