Positional arguments order in clap 3.x #2260
-
Is it possible to determine the order of the positional arguments with the macro system? #[derive(Clap)]
#[clap(version = "0.1.0", author = "JohnnyJayJay")]
pub struct MainOpts {
/// File to output the result of the operation to.
#[clap(short, long, value_name = "FILE")]
pub output: Option<PathBuf>,
#[clap(subcommand)]
pub cmd: SubCommand,
/// input file
#[clap(index = 1)]
pub file: PathBuf,
} And I want it to be interpreted like this: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Have you tried changing the order of the fields? |
Beta Was this translation helpful? Give feedback.
-
You can use the #[clap(short, long, value_name = "FILE", index = 1)]
#[clap(short, long, value_name = "SUBCOMMAND", index = 0)] |
Beta Was this translation helpful? Give feedback.
-
Can positional arguments be in any order? That is, whether the argument content is consumed depends on whether the parsing is successful. |
Beta Was this translation helpful? Give feedback.
You can use the
index(0)
method.