command :create_single do |c|
c.argument :file, String, "The name of the file, without the ext"
c.argument :ext, String, "The ext of the file"
c.action do |file, ext, options|
# the file/ext argment is mapped to the argument set, not an array (i.e. they return strings)
end
end
command :create_multi do |c|
c.arguments :files, List, "The name of the files, without the ext"
c.action do |files, options|
# the files value would be an array of the arguments
end
end
You can only have one arguments declaration.
And it would be neat to mix the two and add the ability to mark required: (pay close attention to the args passed into the action block on this one, they show the outcome:
command :create_multi do |c|
c.argument :base_file, String, "The file to base the other files on", :required => true
c.arguments :files, List, "The name of the files, without the ext", :required => true
c.argument :ext, String, "The ext of the file"
c.action do |base_file, files, ext, options|
# base_file => string
# files => array
# ext => string
# options => hash
end
end
something create_multi base.rb file1 file2 file3 rbx
Note how base.rb and rbx would get mapped as strings, but the rest as array.