Add type coercion option to ARGV.getopts arguements.
I suggest a little new feature to lib/optparse.rb.
When I created CLI tool I defined option parser with
ARGV.getopts function like following.
ARGV.getopts('abc:', 'logopt, 'optwithval:val')
It was so easy and short to recognize what is declared as options, but I could't force a type of the values.
Maybe it looks unshapely, but I'd like to confirm the types like this:
ARGV.getopts('strval:(String)intval:(Integer)', 'logopt', 'optwithval:val(String)')
Normal OptParser has type coercion but extended function
ARGV.getopts has no feature like this.
This difference is trivial but inconvenient.
Updated by nobu (Nobuyoshi Nakada) about 4 years ago
- Status changed from Open to Feedback
- Description updated (diff)
ARGV.getopts is an easy wrapper for old getopts.rb, not recommended.
And I don't like the idea to use names there.
ARGV.getopts("", ["strval:string option", String], ["intval:integer"=>Integer])
ARGV.getopts("", "strval:string option"=>String, "intval:integer"=>Integer)
may be acceptable?
Updated by timakin (Seiji Takahashi) about 4 years ago
Thanks for quick reply!
Former one looks better.
Honestly, I don't know a detail process to contribute, but can I make a pull-req to implement this?
Or is it not acceptable due to the function is not recommended?