Class: CC::CLI::Runner
- Inherits:
-
Object
- Object
- CC::CLI::Runner
- Defined in:
- lib/cc/cli/runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
- #command_arguments ⇒ Object
- #command_class ⇒ Object
- #command_not_found ⇒ Object
-
#initialize(args) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Runner
Returns a new instance of Runner.
17 18 19 |
# File 'lib/cc/cli/runner.rb', line 17 def initialize(args) @args = args end |
Class Method Details
Instance Method Details
#command ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cc/cli/runner.rb', line 52 def command command_name = @args.first case command_name when nil, "-h", "-?", "--help" "help" when "-v", "--version" "version" else command_name end end |
#command_arguments ⇒ Object
48 49 50 |
# File 'lib/cc/cli/runner.rb', line 48 def command_arguments Array(@args[1..-1]) end |
#command_class ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cc/cli/runner.rb', line 37 def command_class command_const = Command[command] if command_const.abstract? nil else command_const end rescue NameError nil end |
#command_not_found ⇒ Object
32 33 34 35 |
# File 'lib/cc/cli/runner.rb', line 32 def command_not_found $stderr.puts "unknown command #{command}" exit 1 end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cc/cli/runner.rb', line 21 def run VersionChecker.new.check if check_version? if command_class command = command_class.new(command_arguments) command.execute else command_not_found end end |