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.
16 17 18 |
# File 'lib/cc/cli/runner.rb', line 16 def initialize(args) @args = args end |
Class Method Details
Instance Method Details
#command ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cc/cli/runner.rb', line 51 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
47 48 49 |
# File 'lib/cc/cli/runner.rb', line 47 def command_arguments Array(@args[1..-1]) end |
#command_class ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cc/cli/runner.rb', line 36 def command_class command_const = Command[command] if command_const.abstract? nil else command_const end rescue NameError nil end |
#command_not_found ⇒ Object
31 32 33 34 |
# File 'lib/cc/cli/runner.rb', line 31 def command_not_found $stderr.puts "unknown command #{command}" exit 1 end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cc/cli/runner.rb', line 20 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 |