Class: Lexdrill::CLI
- Inherits:
-
Object
- Object
- Lexdrill::CLI
- 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
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #start ⇒ Object
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
#argv ⇒ Object (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
#start ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/lexdrill/cli.rb', line 20 def start command = argv.first || "help" handler = COMMANDS.find { |_method, | .include?(command) }&.first return print_unknown_command(command) unless handler send(handler) end |