go-flags icon indicating copy to clipboard operation
go-flags copied to clipboard

feat: Support terminated options like ``find -exec``

Open rebornplusplus opened this issue 2 years ago • 1 comments

feat: Support terminated options like find -exec

Enable option to receive arguments until specified terminator is reached or EOL has been found. This is inspired from find -exec [commands..] ; where commands.. is treated as arguments to -exec.

If for an option opt, terminator is specified to be ; (semi-colon), in the following

$ program [options] --opt v --w=x -- "y z" \; [more-options]

--opt will receive {"v", "--w=x", "--", "y z"} as its argument. Note that, the -- inside will also be passed to --opt regardless PassDoubleDash is set or not. However, once the scope of --opt is finished, i.e. terminator ; is reached, -- will act as before if PassDoubleDash is set.

Use tag terminator to specify the terminator for the option related to that field.

Please note that, the specified terminator should be a separate token, instead of being jotted with other characters. For example,

--opt [arguments..] ; [options..]

will be correctly parsed with terminator: ";". However,

--opt [arguments..] arg; [options..]

will not be correctly parsed. The parser will pass "arg;", and continue to look for the terminator in [options..].

rebornplusplus avatar Feb 01 '23 12:02 rebornplusplus

Hi @benhoyt, thanks for your comments and suggestions! I have updated the PR. Could you please take another look?

rebornplusplus avatar Feb 22 '23 08:02 rebornplusplus