Skip to content

Port ls argument surface from uutils via codegen #1531

@chaliy

Description

@chaliy

Background

crates/bashkit/src/builtins/ls.rs is 3,605 LoC of handwritten flag parsing — the largest single GNU-parity gap in bashkit's coreutils port table. uu_ls's uu_app() is also the largest clap definition in uutils, so this port is the natural pressure test for the codegen tool: if it survives ls, the rest of coreutils is mechanical.

The PR also forces useful upgrades to bashkit-coreutils-port if uu_ls's en-US.ftl uses Fluent placeables or selectors that the current rewriter does not yet handle.

Acceptance criteria

  • crates/bashkit/src/builtins/generated/ls_args.rs produced by cargo run -p bashkit-coreutils-port -- /tmp/uutils ls <REV>. If codegen aborts with unresolved translate!() for Fluent placeables/selectors, upgrade the codegen tool to handle the cases uu_ls exercises before committing the output.
  • pub mod ls_args; added to crates/bashkit/src/builtins/generated/mod.rs.
  • crates/bashkit/src/builtins/ls.rs switches its argument parser to ls_command().try_get_matches_from(...). Existing rendering logic stays put; the change is parser-only at this issue's scope.
  • Flags accepted by uu_ls but not yet implemented by bashkit return an explicit "not yet implemented" error matching the existing tac -b/-r/-s pattern (no silent no-op).
  • GNU help layout — Usage: first — via the same .help_template(...) chain cat.rs and textrev.rs apply.
  • tests/spec_cases/bash/help-flag.test.sh ls_help continues to pass; ls_version updated if the version line format diverges.
  • Spec tests in tests/spec_cases/bash/ cover: at least three short flags from uu_ls that bashkit previously parsed loosely (e.g. -Q, --quoting-style=, --group-directories-first), one composite scenario, and unknown-flag rejection (with ### bash_diff for the clap-vs-GNU exit-code difference).
  • coreutils-args-drift.yml picks up ls_args automatically via the existing pub mod ... grep — no workflow edit required.
  • Every existing ls spec test stays green.
  • Compiled binary size delta on cargo build -p bashkit-cli --release is reported in the PR description (the cat/tac POC was +9 KB declared-but-unused; ls is fully wired so a real number is meaningful).

Out of scope

  • Implementing every uu_ls option (--context, --si, --block-size, full coloration). Leave them parser-accepted-with-explicit-error or wire them to existing bashkit logic only when straightforward.
  • Vendoring uucore::quoting-style for --quoting-style semantics — separate question, see the module-vendor mode issue.

Open questions

  • Does the codegen tool's translate!() rewriter need to handle Fluent placeables ({ $count }, { $name }) and selectors that appear in uu_ls's about/help strings? If yes, the port-tool gets a Phase-2 enhancement before this PR can land cleanly.
  • The codegen output for ls is large (hundreds of args). Measure the cost of try_get_matches_from on every ls invocation against the current handwritten parser. Cache ls_command() in a OnceLock if the construction overhead is meaningful.

Related

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