Skip to content
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

Add 'remainder': greedy positional arguments #143

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

stormbrew
Copy link
Contributor

This adds a new variant of positional arguments that, once they start processing, consume all arguments after as part of the positional argument, as if they always had '--' in front or behind them.

We need this for deferring subcommand parsing in ffx until after we've read the main command's arguments.

argh/src/lib.rs Outdated
// Don't increment position if we're at the last arg
// *and* the last arg is repeating. If it's also remainder,
// halt non-option processing after this.
println!("{}", self.last_is_greedy);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like some debug code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow yep, that would have been unfortunate to leave in. Good catch.

c: None,
d: vec!["foo".into(), "bar".into(), "--c".into(), "hi".into()],
},
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add a check that this still plays nicely with --? With something like:

        assert_output(
            &["5", "foo", "bar", "--", "hi"],
            LastRepeatingGreedy {
                a: 5,
                b: false,
                c: None,
                d: vec!["foo".into(), "bar".into(), "--".into(), "hi".into()],
            },
        );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure.

This adds a new variant of positional arguments that, once they start
processing, consume all arguments after as part of the positional
argument, as if they always had '--' in front or behind them.
@erickt erickt merged commit fa20b09 into google:master Sep 22, 2022
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