Is there any way to kick off optparse
several times in one Ruby program, each with different sets of options?
Example:
$ myscript.rb --subsys1opt a --subsys2opt b
here, myscript.rb would use subsys1 and subsys2, delegating their options handling logic to them, possibly in a sequence where 'a' is processed first, followed by 'b' in separate OptParser object; each time picking options only relevant for that context.. A final phase could check that there is nothing unknown left after each part processed theirs.
Use cases:
in a loosely coupled -frontend- program , where various components have different arguments, I don't want 'main' to know about everything, just to delegate sets of arguments/options to each part
Embedding some larger system like RSpec into my application, and I'd to simply pass command line through their options without my wrapper knowing those.
I'd be OK with some delimiter option as well, like '--' or '--vmargs' in some Java apps.
There are lots of real world examples for similar things in the Unix world (startx/X, git plumbing and porcelain), where one layer handles some options but propagates the rest to the lower layer.
Out of the box, this doesn't seem to work: each OptionParse.parse! calls will do an exhaustive processing, failing on anything it doesn't know about. I guess i'd happy to skip unknown options. Any hints, perhaps alternative approaches are welcome.