Skip to content

fix(cli): sort top-level help with clap display order - #836

Merged
platinummonkey merged 3 commits into
DataDog:mainfrom
MintsInc:ulysse.mavrocordatos/AAWF-1386/sort-help-display-order
Sep 18, 2026
Merged

platinummonkey merged 3 commits into
DataDog:mainfrom
MintsInc:ulysse.mavrocordatos/AAWF-1386/sort-help-display-order

Conversation

@MintsInc

@MintsInc MintsInc commented Sep 18, 2026

Copy link
Copy Markdown
Member

Context

pup#269 established that top-level commands in pup --help should be alphabetically sorted. Enum declaration order was a valid proxy while every command was hand-written, but #[command(flatten)] keeps generated commands contiguous and prevents them from being interleaved with hand-written variants.

This caused pup#829 to render generated commands such as downtimes at the end of help instead of between downtime and error-tracking.

Using separate hand-written and generated blocks was considered, but clap provides only one top-level command heading, so the result would look incorrectly sorted and become more pronounced as generation expands. Assigning a shared display order lets clap sort the complete command list by name. Display order affects help placement only; command parsing is unchanged.

Clap checks duplicate command names and aliases only in debug builds. Because a duplicate top-level name or alias can behave ambiguously in release builds, this PR adds an explicit uniqueness regression test across generated and hand-written commands.

Changes

  • Add a shared clap command constructor that assigns the same display order to every top-level subcommand.
  • Use the constructor for runtime parsing, agent-help schema construction, and the command tree passed to static shell completion generators.
  • Document that display-order normalization applies only to top-level commands.
  • Retarget the existing alphabetical-order regression test at rendered help instead of enum insertion order.
  • Parse only command rows within the rendered Commands: section, excluding wrapped descriptions and later help sections.
  • Add regression coverage for uniform display order, alphabetical interleaving, and unique top-level command names and aliases, including hidden aliases.

Tests

  • cargo build
  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test -- --test-threads=1 — 2,018 passed
  • Verified pup --help remains alphabetically sorted.
  • Verified pup --agent --help still emits the agent schema.
  • Verified Bash and Zsh completion generation succeeds.
  • Browser WASM build was not run locally because the wasm32-unknown-unknown target and rustup are unavailable; CI covers this configuration.

Use a shared clap command constructor so generated and hand-written commands are alphabetized together in help and completions. Retarget the regression test at rendered help and cover an appended out-of-order command.
Use the shared command constructor for agent help, enforce unique top-level names and uniform display order, and make rendered-help parsing robust to wrapped descriptions and later help sections.
Prevent top-level command names and both visible and hidden aliases from colliding across hand-written and generated commands.
@MintsInc
MintsInc marked this pull request as ready for review September 18, 2026 13:09
@MintsInc
MintsInc requested a review from a team as a code owner September 18, 2026 13:09
@platinummonkey
platinummonkey merged commit 9aefc00 into DataDog:main Sep 18, 2026
6 checks passed
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.

2 participants