Skip to content

feat: Support terminated options like find -exec#395

Open
rebornplusplus wants to merge 1 commit intojessevdk:mainfrom
rebornplusplus:terminated-options
Open

feat: Support terminated options like find -exec#395
rebornplusplus wants to merge 1 commit intojessevdk:mainfrom
rebornplusplus:terminated-options

Conversation

@rebornplusplus
Copy link
Copy Markdown

@rebornplusplus rebornplusplus commented Feb 1, 2023

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 pushed a commit to rebornplusplus/pebble that referenced this pull request Feb 8, 2023
The upstream go-flags project do not support terminated options
like ``find -exec``. The repo was forked and the feature was
introduced in [0].

Until the PR [1] is merged in the upstream repo, we need to
maintain and point to a fork with the features there.

Refs:
- [0] rebornplusplus/go-flags@1dbaf44
- [1] jessevdk/go-flags#395
Copy link
Copy Markdown

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall idea looks reasonable to me, but I have a few comments related to making it more general and cleaning it up a bit.

Comment thread group.go Outdated
Comment thread group.go Outdated
Comment thread group.go
Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread options_test.go Outdated
Comment thread options_test.go
Comment thread options_test.go Outdated
Comment thread parser.go Outdated
Comment thread options_test.go
@rebornplusplus rebornplusplus force-pushed the terminated-options branch 2 times, most recently from df1e3bf to 92578f9 Compare February 22, 2023 08:53
@rebornplusplus
Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a couple of minor nits comments (and I kinda disagree --term \; that should be disallowed).

Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread option.go Outdated
Comment thread options_test.go Outdated
Comment thread parser.go Outdated
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..].
@benhoyt
Copy link
Copy Markdown

benhoyt commented Apr 13, 2026

(Just going through some old PRs I've commented on.) Any plans to integrate this? If not, it's probably best to close this. FWIW, we integrated it into our fork in canonical#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants