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.
15 16 17 |
# File 'lib/cc/cli/runner.rb', line 15 def initialize(args) @args = args end |
Class Method Details
.run(argv) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/cc/cli/runner.rb', line 7 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
51 52 53 |
# File 'lib/cc/cli/runner.rb', line 51 def command @args.first end |
#command_arguments ⇒ Object
47 48 49 |
# File 'lib/cc/cli/runner.rb', line 47 def command_arguments @args[1..-1] end |
#command_class ⇒ Object
33 34 35 36 37 |
# File 'lib/cc/cli/runner.rb', line 33 def command_class CLI.const_get(command_name) rescue NameError nil end |
#command_name ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/cc/cli/runner.rb', line 39 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
28 29 30 31 |
# File 'lib/cc/cli/runner.rb', line 28 def command_not_found $stderr.puts "unknown command #{command}" exit 1 end |
#run ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/cc/cli/runner.rb', line 19 def run if command_class command = command_class.new(command_arguments) command.execute else command_not_found end end |