Skip to content

feat(true,false): print Usage: line before the description in --help#12815

Open
koopatroopa787 wants to merge 2 commits into
uutils:mainfrom
koopatroopa787:true-false-usage-first
Open

feat(true,false): print Usage: line before the description in --help#12815
koopatroopa787 wants to merge 2 commits into
uutils:mainfrom
koopatroopa787:true-false-usage-first

Conversation

@koopatroopa787

Copy link
Copy Markdown
Contributor

Fixes #10279

true --help/false --help were missing the leading "Usage:" line that GNU prints first:

$ LANG=C cargo run -q --features unix false --help | head -1
Returns false, an unsuccessful exit status.

vs GNU:

$ LANG=C /usr/bin/false --help | head -1
Usage: /usr/bin/false [ignored command line arguments]

As discussed on the issue, scoping this to true/false first rather than changing the global help template (which would affect every utility's --help output).

Changes

  • Added localized_help_template_usage_first() to uucore, a variant of localized_help_template() that places the localized "Usage:" line before {about-with-newline} instead of after. The default ordering used by every other utility is unchanged (refactored the shared logic into a private localized_help_template_with_order() helper, verified with cargo clippy/cargo fmt).
  • Added true-usage / false-usage Fluent strings (en-US + fr-FR) modeled on GNU's Usage: true [ignored command line arguments]\n or: true OPTION, wired up via .override_usage(format_usage(&translate!(...))).
  • Added test_help_starts_with_usage to test_true.rs / test_false.rs asserting --help output starts with the new Usage: line.

Before / after

$ cargo run -q -p uu_false --bin false -- --help
Usage: false [ignored command line arguments]
       or:  false OPTION

Returns false, an unsuccessful exit status.

Immediately returns with the exit status 1. ...

Test plan

  • cargo test --test tests --features "true false" -- test_true test_false — 14/14 pass
  • cargo test --test test_localization_and_colors — 5/5 pass (en/fr help + error message localization unaffected)
  • cargo fmt -- --check clean
  • cargo clippy -p uu_true -p uu_false -p uucore --no-deps clean
  • Spot-checked other utilities (e.g. pwd --help) to confirm the default about-first ordering is unchanged

GNU's `true --help`/`false --help` start with a "Usage:" synopsis
line, but uutils printed the long description first instead:

  $ LANG=C false --help | head -1
  Returns false, an unsuccessful exit status.

vs. GNU:

  $ LANG=C /usr/bin/false --help | head -1
  Usage: /usr/bin/false [ignored command line arguments]

Adds a `localized_help_template_usage_first()` helper in uucore that
places the localized "Usage:" line before `{about-with-newline}`
(the default ordering for every other utility is unchanged), and
gives true/false their own `*-usage` strings ("true [ignored command
line arguments] / or: true OPTION", and similarly for false) wired up
via `override_usage`.
Copilot AI review requested due to automatic review settings June 12, 2026 16:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds GNU-aligned help output for true/false by moving the “Usage:” synopsis ahead of the description and overriding the usage synopsis text, with new tests asserting the behavior.

Changes:

  • Introduce a localized_help_template_usage_first help template variant in uucore
  • Override true/false usage strings via localized *-usage messages and override_usage
  • Add integration tests asserting --help starts with the expected usage synopsis

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/by-util/test_true.rs Adds a test asserting true --help begins with the expected usage synopsis
tests/by-util/test_false.rs Adds a test asserting false --help begins with the expected usage synopsis
src/uucore/src/lib/lib.rs Adds a “usage first” localized help template and refactors color detection into a helper
src/uu/true/src/true.rs Switches to usage-first template and overrides usage with a localized string
src/uu/true/locales/fr-FR.ftl Adds localized true-usage string
src/uu/true/locales/en-US.ftl Adds English true-usage string
src/uu/false/src/false.rs Switches to usage-first template and overrides usage with a localized string
src/uu/false/locales/fr-FR.ftl Adds localized false-usage string
src/uu/false/locales/en-US.ftl Adds English false-usage string

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +41
// GNU's `true --help` starts with a "Usage:" line; ensure ours does too.
let result = new_ucmd!().args(&["--help"]).succeeds();
assert!(
result
.stdout_str()
.starts_with("Usage: true [ignored command line arguments]")
);
Comment on lines +32 to +38
// GNU's `false --help` starts with a "Usage:" line; ensure ours does too.
let result = new_ucmd!().args(&["--help"]).fails();
assert!(
result
.stdout_str()
.starts_with("Usage: false [ignored command line arguments]")
);
Comment thread src/uucore/src/lib/lib.rs
Comment on lines +301 to 314
/// Determine whether colored output should be used, based on the same
/// environment variables and TTY checks as `configure_localized_command`.
fn detect_colors_enabled() -> bool {
use std::io::IsTerminal;

// Determine if colors should be enabled - same logic as configure_localized_command
let colors_enabled = if std::env::var("NO_COLOR").is_ok() {
if std::env::var("NO_COLOR").is_ok() {
false
} else if std::env::var("CLICOLOR_FORCE").is_ok() || std::env::var("FORCE_COLOR").is_ok() {
true
} else {
IsTerminal::is_terminal(&std::io::stdout())
&& std::env::var("TERM").unwrap_or_default() != "dumb"
};

localized_help_template_with_colors(util_name, colors_enabled)
}
}
@codspeed-hq

codspeed-hq Bot commented Jun 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 321 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation complex_relative_date 134.2 µs 142.5 µs -5.82%
Simulation ls_recursive_wide_tree[(10000, 1000)] 34.3 ms 33.2 ms +3.38%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing koopatroopa787:true-false-usage-first (f8b8582) with main (048f56e)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/tail/truncate. tests/tail/truncate is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/timeout/timeout-group (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Skip an intermittent issue tests/cut/bounded-memory (was skipped on 'main', now failing)
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

- Set NO_COLOR=1 in the new --help tests so the starts_with("Usage: ...")
  assertion doesn't break when CLICOLOR_FORCE/FORCE_COLOR are set.
- Deduplicate color-detection logic: detect_colors_enabled() now reuses
  clap_localization::should_use_color_for_stream() instead of
  re-implementing the same NO_COLOR/CLICOLOR_FORCE/FORCE_COLOR/TERM checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

missing "Usage:" in true/false

2 participants