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_name ⇒ 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 19 20 |
# File 'lib/cc/cli/runner.rb', line 16 def initialize(args) SafeYAML::OPTIONS[:default_mode] = :safe @args = args end |
Class Method Details
.run(argv) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/cc/cli/runner.rb', line 8 def self.run(argv) new(argv).run rescue => ex $stderr.puts("error: (#{ex.class}) #{ex.message}") CLI.debug("backtrace: #{ex.backtrace.join("\n\t")}") end |
Instance Method Details
#command ⇒ Object
54 55 56 |
# File 'lib/cc/cli/runner.rb', line 54 def command @args.first end |
#command_arguments ⇒ Object
50 51 52 |
# File 'lib/cc/cli/runner.rb', line 50 def command_arguments @args[1..-1] end |
#command_class ⇒ Object
36 37 38 39 40 |
# File 'lib/cc/cli/runner.rb', line 36 def command_class CLI.const_get(command_name) rescue NameError nil end |
#command_name ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cc/cli/runner.rb', line 42 def command_name case command when nil, "-h", "-?", "--help" then "Help" when "-v", "--version" then "Version" else command.sub(":", "::").underscore.camelize end 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
22 23 24 25 26 27 28 29 |
# File 'lib/cc/cli/runner.rb', line 22 def run if command_class command = command_class.new(command_arguments) command.execute else command_not_found end end |