Skip to content

Allow the user to stop processing flags after seeing N args #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adrian-thurston
Copy link

@adrian-thurston adrian-thurston commented Jun 24, 2025

What type of PR is this?

  • feature

What this PR does / why we need it:

We have switched from v2 to v3 mainly because we want to support flags after the arguments. There are many other benefits, but this one drove the work.

We do have some commands though where the old v2 behaviour is desirable, specifically, when we pass arguments through. For example our ssh command:

  tool ssh MACHINE-NAME ls -la

It is possible to require the user to use the special argument --, however we would prefer to not disrupt existing usage where the old bahaviour is relied on.

To support this per-command, added an option to the Command struct called StopOnNthArg. It terminates flag parsing after seeing N positional arguments.

Which issue(s) this PR fixes:

There is no issue for this that I am aware of.

Special notes for your reviewer:

Using a pointer to int might be considered odd. Maybe there is a project convention to follow?

Testing

Test cases for the feature have been added.

Release Notes

New feature: allow the user to stop processing flags after seeing N args.

@adrian-thurston adrian-thurston requested a review from a team as a code owner June 24, 2025 22:20
@adrian-thurston adrian-thurston marked this pull request as draft June 24, 2025 23:28
@adrian-thurston adrian-thurston force-pushed the feat/stop-on-nth-arg branch 3 times, most recently from 0c5bcbe to 9d3591b Compare June 25, 2025 00:40
We have switched from v2 to v3 mainly because we want to support parsing flags
after the arguments. There are many other benefits, but this one drove the
work.

We do have some commands where the old v2 behaviour is desirable, specifically,
when we pass arguments through. For example our ssh command:

  tool ssh MACHINE-NAME ls -la

To support this on a per-command basis, added an option to the Command struct
called StopOnNthArg. It terminates flag parsing like '--'.
@adrian-thurston adrian-thurston marked this pull request as ready for review June 25, 2025 05:25
@adrian-thurston adrian-thurston changed the title feat: allow the user to stop processing flags after seeing N args Allow the user to stop processing flags after seeing N args Jun 25, 2025
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.

1 participant