perlancar / perl-Getopt-Long-More

1 stars 1 forks source link

More stuff: ability to not strip parsed option from @ARGV #24

Open perlancar opened 5 years ago

perlancar commented 5 years ago

I'm writing a few wrappers for Unix command, e.g. rsync-retry, wget-retry, rsynccolor. These wrappers add/override a couple of options (like --help, --version) and pass through the rest to the target Unix command. Sometimes they need to read an option then pass it through. So it would be nice if GLM lets us specify that some options should not be stripped as they are parsed.

For example:

GetOptions(foo => \$opts{foo}, bar => optspec(dest=>\$opt{bar}, retain=>1));

Parsing:

--foo 1 --bar 2

will result in @ARGV becoming ('--bar', 2) and %opts becoming (foo=>1, bar=>2).

tabulon commented 4 years ago

I hear you... There's really an unnecessary startup overhead option-processing for these simple wrapper scenarios.

Although GoL does provide a pass_thru mechanism for the simplest case (for options that don't need to be accessed by the wrapper), that's quite insufficient for most such scenarios.

BTW, any ideas on how to simultanously retain the position of an option in @ARGV while modifying (patching) its value? (which is sometimes needed, though not always).

perlancar commented 4 years ago

BTW, any ideas on how to simultanously retain the position of an option in @argv while modifying patching) its value? (which is sometimes needed, though not always).

Yeah, this will be cumbersome to implement because Getopt::Long does not supply the necessary information to the handler. Either we send a patch/PR to Getopt::Long, e.g. supply this information in Getopt::Long::CallBack, or eventually we fork or implement GetOptionsFromArray ourselves.

tabulon commented 4 years ago

Yupp...