Module: Rake::ToolkitProgram::TaskExt
- Defined in:
- lib/rake/toolkit_program/task_ext.rb
Instance Method Summary collapse
-
#invalid_args!(message) ⇒ Object
Convenience method for raising Rake::ToolkitProgram::InvalidCommandLine.
-
#parse_args(into: ToolkitProgram.new_default_parsed_args {Hash.new}) {|parser, new_args| ... } ⇒ Object
Define argument parsing for a Rake::Task used as a command.
-
#prohibit_args ⇒ Object
Prohibit any arguments when this command is invoked.
Instance Method Details
#invalid_args!(message) ⇒ Object
Convenience method for raising Rake::ToolkitProgram::InvalidCommandLine
The error raised is the standard error for an invalid command line when using Rake::ToolkitProgram.
57 58 59 |
# File 'lib/rake/toolkit_program/task_ext.rb', line 57 def invalid_args!() raise InvalidCommandLine, end |
#parse_args(into: ToolkitProgram.new_default_parsed_args {Hash.new}) {|parser, new_args| ... } ⇒ Object
Define argument parsing for a Rake::Task used as a command
The block receives two arguments:
-
a Rake::ToolkitProgram::CommandOptionParser (a subclass of OptionParser)
-
the argument accumulator object passed in as
into
When the subject task is invoked through Rake::ToolkitProgram.run, the parser configured in this block is run against the remaining arguments (after the command name). The argument accumulator into
will be available as Rake::ToolkitProgram.args instead of the default argument Array.
Rake::ToolkitProgram::CommandOptionParser offers some useful extensions around positional parameters, since the Array containing the remaining arguments after parsing would be otherwise unavailable.
43 44 45 46 47 48 49 |
# File 'lib/rake/toolkit_program/task_ext.rb', line 43 def parse_args(into: ToolkitProgram.new_default_parsed_args {Hash.new}) parser, new_args = CommandOptionParser.new(into), into yield parser, new_args @arg_parser = parser extend ArgParsingTask return self end |
#prohibit_args ⇒ Object
Prohibit any arguments when this command is invoked
Help arguments are still allowed, as the special ‘help’ command is the one invoked when they are present.
67 68 69 |
# File 'lib/rake/toolkit_program/task_ext.rb', line 67 def prohibit_args parse_args(into: []) {|parser| parser.no_positional_args!} end |