I’ve got a ruby bin with some arguments, namely -s, -c and -r (short for scrape, create and run). Now I’d like to set some defaults to scrape and create ('.' in both cases), but if I use :default in trollop, I can’t check wherever that argument is set or not.
project --scrape
should be equivalent to
project --scrape .
how to achieve that?
And while at it, how do I make
project target
to be equivalent with
project --run target
?
You can modify
ARGVbefore Trollop processes it. Your best bet would probably be to scan the input arguments, apply some basic transformations, and then run Trollop.For example:
This snippet should check for
--scrapewith no parameter following it and add in a'.'in that case. You can do something similar to check for the omitted--runparameter. When you are done making your modifications, useargs.join(' ')to put the arguments back together into a string. Assign this new string toARGV, and then set Trollop loose.