clap
clap copied to clipboard
Argument descriptions not aligned when mixing positional arguments with others under a help heading
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
Rust Version
rustc 1.61.0 (fe5b13d68 2022-05-18)
Clap Version
3.2.2
Minimal reproducible code
use clap::Parser;
use std::path::PathBuf;
#[derive(Parser)]
struct Cli {
/// One or more test cases separated by blank space.
#[clap(value_name = "INPUT", value_parser, help_heading = "INPUT")]
input: Vec<String>,
/// Reads test cases on separate lines from a file.
#[clap(
name = "file",
value_name = "FILE",
short,
long,
value_parser,
help_heading = "INPUT"
)]
file_path: Option<PathBuf>
}
fn main() {
let cli = Cli::parse();
}
Steps to reproduce the bug with the above code
- Compile the binary.
- Print the help using
binary -h
.
Actual Behaviour
The help messages are not properly aligned.
INPUT:
-f, --file <FILE> Reads test cases on separate lines from a file
<INPUT>... One or more test cases separated by blank space
Expected Behaviour
The help messages should be properly aligned.
INPUT:
-f, --file <FILE> Reads test cases on separate lines from a file
<INPUT>... One or more test cases separated by blank space
Additional Context
I understand that proper alignment is not always possible or appropriate. Grouped arguments, however, should always be aligned correctly, in my opinion. The problem here is probably that help messages of flags are aligned differently than help messages of arguments receiving arbitrary input.
Debug Output
No response
Thanks for reporting this!
Currently, our help output is making the assumption that positionals and named arguments are in separate sections. Supporting them in the same section will take a little bit of finagling to ensure all of the padding situations work out correctly especially to not over-pad in positional-only cases.
If we can reduce leading padding in long-flag only cases, that'd be a bonus to fixing this.