jessevdk / go-flags

go command line option parser
http://godoc.org/github.com/jessevdk/go-flags
BSD 3-Clause "New" or "Revised" License
2.59k stars 308 forks source link

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

Open rebornplusplus opened 1 year ago

rebornplusplus commented 1 year ago

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 commented 1 year ago

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