- Notifications
You must be signed in to change notification settings - Fork1.1k
Open
Description
Please complete the following tasks
- I have searched thediscussions
- I have searched theopen andrejected issues
Rust Version
1.80.0
Clap Version
4.5.11
Minimal reproducible code
use clap::*;// 4.5.11#[derive(Parser)]structTopLevel{first:String,#[command(flatten)]second:Inner,}// *** Note: the user can specify *either* a positional argument *or* a named argument#[derive(Args)]#[group(required =true, multiple =false)]structInner{value:Option<String>,#[arg(long)]path:Option<String>,}fnmain(){letmut cmd =TopLevel::command(); _ = cmd.print_long_help();let parsed =TopLevel::parse_from(["test","a","b"]);assert_eq!(parsed.first,"a");assert_eq!(parsed.second.value,"b");}
Steps to reproduce the bug with the above code
Run on play.rust-lang.org
Actual Behaviour
Usage: playground <VALUE|--path <PATH>> <FIRST>
even though the assertions show that theFIRST
argument is in fact getting parsed first, as desired.
Expected Behaviour
Usage: playground <FIRST> <VALUE|--path <PATH>>
It does work to put the flag argument after the first positional argument, so this isn't even wrong, even if it's a little unconventional.
Additional Context
I tried manually specifyingindex
on the arguments, but it did not affect the help output.
Debug Output
No response