Skip to content

Why Arg::last requires double dash -- even if no other arguments left to parse? #2292

Answered by ldm0
lnyng asked this question in Q&A
Discussion options

You must be logged in to vote

Tracking issue of Arg::Last: #888

The related code is here:

clap/src/parse/parser.rs

Lines 517 to 528 in 50fb4ca

pos_counter += 1;
}
} else if self.is_set(AS::TrailingValues)
&& (self.is_set(AS::AllowMissingPositional) || self.is_set(AS::ContainsLast))
{
// Came to -- and one positional has .last(true) set, so we go immediately
// to the last (highest index) positional
debug!("Parser::get_matches_with: .last(true) and --, setting last pos");
pos_counter = positional_count;
}
if let Some(p) = self

It's by design, according to the issue and the code. You can create an issue for discussion. (BTW, I think the behaviour i…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@lnyng
Comment options

@pksunkara
Comment options

Comment options

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