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.
19 20 21 22 23 |
# File 'lib/cc/cli/runner.rb', line 19 def initialize(args) SafeYAML::OPTIONS[:default_mode] = :safe @args = args end |
Class Method Details
.run(argv) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/cc/cli/runner.rb', line 9 def self.run(argv) new(argv).run rescue => ex $stderr.puts("error: (#{ex.class}) #{ex.}") if ENV["CODECLIMATE_DEBUG"] $stderr.puts("backtrace: #{ex.backtrace.join("\n\t")}") end end |
Instance Method Details
#command ⇒ Object
57 58 59 |
# File 'lib/cc/cli/runner.rb', line 57 def command @args.first end |
#command_arguments ⇒ Object
53 54 55 |
# File 'lib/cc/cli/runner.rb', line 53 def command_arguments @args[1..-1] end |
#command_class ⇒ Object
39 40 41 42 43 |
# File 'lib/cc/cli/runner.rb', line 39 def command_class CLI.const_get(command_name) rescue NameError nil end |
#command_name ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/cc/cli/runner.rb', line 45 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
34 35 36 37 |
# File 'lib/cc/cli/runner.rb', line 34 def command_not_found $stderr.puts "unknown command #{command}" exit 1 end |
#run ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/cc/cli/runner.rb', line 25 def run if command_class command = command_class.new(command_arguments) command.execute else command_not_found end end |