trevorld / r-argparse

command-line optional and positional argument parser
https://trevorldavis.com/R/argparse/
GNU General Public License v2.0
104 stars 11 forks source link

Support for `choices` would be nice #3

Closed metasoarous closed 10 years ago

metasoarous commented 10 years ago

If I do something like

parser$add_argument('-s', '--sort-by', choices=list("this", "that"))

I get the following usage:

-s {l,i,s,t,(,",t,h,i,s,",,, ,",t,h,a,t,",)}, --sort-by {l,i,s,t,(,",t,h,i,s,",,, ,",t,h,a,t,",)}

Which is obviously not what we want. It does something similar when I use a vector instead of a list.

Is there some way with to get around this as currently written?

trevorld commented 10 years ago

Extended my utility function convert_..._to_arguments to handle choices argument.

Please test the development version::

devtools::install_github("argparse", "trevorld")

Character vectors should work. Not sure about lists...

metasoarous commented 10 years ago

Brilliant; it works! Thank you for your rapid response!