module Thor::Base::ClassMethods
def argument(name, options={})
ArgumentError:: Raised if you supply a required argument after a non required one.
==== Errors
:banner - String to show on usage notes.
:default - Default value for this argument. It cannot be required and have default values.
:type - The type of the argument, can be :string, :hash, :array, :numeric.
:optional - If the argument is optional or not.
:required - If the argument is required or not.
:desc - Description for the argument.
==== Options
options
name
==== Parameters
try it, an error is raised.
you cannot have a required argument after a non-required argument. If you
optional (supplying :optional => :true or :required => false), although
Finally, arguments cannot have type :default or :boolean but can be
while options are all kept in a hash (self.options).
Besides, arguments are used inside your code as an accessor (self.argument),
thor task --name=NAME
Instead of:
thor task NAME
from position:
is how they are parsed from the command line, arguments are retrieved
Arguments are different from options in several aspects. The first one
Adds an argument to the class and creates an attr_accessor for it.
def argument(name, options={}) is_thor_reserved_word?(name, :argument) no_tasks { attr_accessor name } required = if options.key?(:optional) !options[:optional] elsif options.key?(:required) options[:required] else options[:default].nil? end remove_argument name arguments.each do |argument| next if argument.required? raise ArgumentError, "You cannot have #{name.to_s.inspect} as required argument after " << "the non-required argument #{argument.human_name.inspect}." end if required arguments << Thor::Argument.new(name, options[:desc], required, options[:type], options[:default], options[:banner]) end