Closed kiall closed 13 years ago
Default values and validation sounds great and I can take care of that soon :) required parameters can be handled by validation, no?
I'm not too sure how the array values and the -q/-v options would be implemented, what are your ideas? How do all other CLI applications handle these kinds of things? I like how some allow you to use -vv
or similar for a more verbose output than -v
.
required parameters can be handled by validation, no?
Spot on .. But thought it should be mentioned explicitly :)
The -q vs --quiet etc will be harder to do right.. I'm not even sure what really is right :)
Here's a quick ruby example:
# Boolean flag
options[:verbose] = false # Default Value
opts.on("-v", "--verbose", "Verbose") do
options[:verbose] = true
end
# List of arguments
options[:modules] = Array.new() # Default Value
opts.on("-m", "--modules x,y,z", Array, "Example 'list' of arguments") do |value|
options[:modules] = value
end
# List of arguments and no short form ..
options[:modules] = Array.new() # Default Value
opts.on("--modules x,y,z", Array, "Example 'list' of arguments") do |value|
options[:modules] = value
end
# The "LIBRARY" argument to the -r switch is mandatory
options[:libs] = Array.new() # Default values
opts.on("-r", "--require LIBRARY") do |value|
options[:libs] << value
end
# The "STRING" argument to the -s switch is optional
opts.on("-s", "--print [LIBRARY]") do |value|
puts value
end
# Cast 'time' argument to a Time object.
options[:time] = Time.new() # Default Value
opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |value|
options[:time] = value
end
I created smaller tickets for the features here. Closing this ticket in favor of the following: #42 #43 #44 #45 #46
Let me know if I missed any
Has any thought gone into adding more features to the command line option parser? If not .. what about these suggestions?
Things like: