Skip to content

Is it possible to require arguments to be "in order"? #5413

Answered by pfmoore
pfmoore asked this question in Q&A
Discussion options

You must be logged in to vote

And the final version, which is impressively straightforward:

struct Args {
    #[arg(short, long)]
    include: Vec<String>,
    script: String,
    #[arg(trailing_var_arg=true, allow_hyphen_values=true)]
    script_args: Vec<String>,
}

trailing_var_arg lets the last positional argument pick everything up, and allow_hyphen_values ensures that it accepts arguments with leading hyphens, rather than trying to parse them as options.

Sorry I didn't manage to find this myself in the first place - my search skills were obviously lacking. The key result that set me on the right path was here.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
6 replies
@epage
Comment options

@pfmoore
Comment options

@pfmoore
Comment options

@epage
Comment options

@pfmoore
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by pfmoore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants