Class: CP::Runners::CmdParse
Instance Method Summary collapse
-
#initialize(app) ⇒ CmdParse
constructor
A new instance of CmdParse.
- #run(*args) ⇒ Object
- #runner ⇒ Object
Constructor Details
#initialize(app) ⇒ CmdParse
Returns a new instance of CmdParse.
7 8 9 |
# File 'lib/cp/runners/cmd_parse.rb', line 7 def initialize( app ) @app = app end |
Instance Method Details
#run(*args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cp/runners/cmd_parse.rb', line 11 def run( *args ) command_name = '' begin runner.parse( args ) { |l, c| command_name << "#{c} " if l > 0 } rescue ::CmdParse::InvalidCommandError => e command_name << e..gsub( /^.*: /, '' ) CP::App.instance.fatal( "'#{command_name}' is not a #{CP::App.instance.name} command" ) rescue ::CmdParse::InvalidOptionError, ::OptionParser::InvalidOption => e switch = e..gsub( /^.*: /, '' ) CP::App.instance.fatal( "'#{switch}' is not a valid option" ) end end |
#runner ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cp/runners/cmd_parse.rb', line 28 def runner runner = ::CmdParse::CommandParser.new runner.program_name = @app.name runner.program_version = @app.version ? @app.version.split( "." ) : nil ( runner, @app. ) add_commands( runner, @app.commands ) unless @app.commands[:help] has_default_command = @app.commands.values.find { |c| c.default } runner.add_command( ::CmdParse::HelpCommand.new, !has_default_command ) end runner end |