Skip to content

bug: Help text wraps based on format string variable name length, not rendered value length #236

Description

@vamea

Bug Description

When using variable interpolation in argh's description attribute, the help text wrapping algorithm incorrectly uses the length of the variable name rather than the actual rendered value, causing inconsistent and incorrect line breaks in the generated help output.

This bug is present in argh v0.1.9 and 939affd.

Expected Behaviour

Help text should wrap based on the actual rendered output length, not the substitution variable name used in the Rust source code.

Actual Behaviour

  • Using a long variable name like DEFAULT_ARGUMENT_VALUE causes wrapping even if the rendered value is short (e.g., 0).

  • Using a short variable name like D does not wrap, even if the actual value is longer.

Reproduction

const DEFAULT_ARGUMENT_VALUE: u64 = 0;
const D: u64 = u64::MAX;

#[derive(argh::FromArgs)]
#[argh(description = "the help command has a bug\n\n")]
struct CliArgs {
    #[argh(
        option,
        short = 'f',
        default = "DEFAULT_ARGUMENT_VALUE",
        description = "this is a flag that does foo [default: {DEFAULT_ARGUMENT_VALUE}]"
    )]
    foo: u64,

    #[argh(option, short = 'b', default = "D", description = "{D} {D} {D} {D}")]
    bar: u64,
}

fn main() {
    let args: CliArgs = argh::from_env();
    println!("foo={}", args.foo);
    println!("bar={}", args.bar);
}

Output

$ ./target/release/bugreport help
Usage: bugreport [-f <foo>] [-b <bar>]

the help command has a bug

Options:
  -f, --foo         this is a flag that does foo [default:
                    0]
  -b, --bar         18446744073709551615 18446744073709551615 18446744073709551615 18446744073709551615
  --help, help      display usage information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions