google / google/argh

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

Open
#236 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
2k
Forks
102
PR merge metrics
No merged PRs in 30d

Description

## 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](https://github.com/google/argh/releases/tag/v0.1.19) and 939affd3acc60395bb34749cabb80cc19bcd20eb.

## 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

```rs
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 ] [-b ]

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
```

Contributor guide

Open the contributing guide

Research direction

No source file or test is named in the issue. Start by running the provided Rust reproduction and trace argh's help-text interpolation and wrapping logic; done means wrapping follows the rendered values for both long and short variable names, with regression coverage for the shown cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.