module Rake::ToolkitProgram::TaskExt
Public Instance Methods
Convenience method for raising Rake::ToolkitProgram::InvalidCommandLine
The error raised is the standard error for an invalid command line when using Rake::ToolkitProgram
.
# File lib/rake/toolkit_program/task_ext.rb, line 57 def invalid_args!(message) raise InvalidCommandLine, message end
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.
# 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 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.
# File lib/rake/toolkit_program/task_ext.rb, line 67 def prohibit_args parse_args(into: []) {|parser| parser.no_positional_args!} end