feat(builtins): port ls argument surface from uutils via codegen#1560
Merged
feat(builtins): port ls argument surface from uutils via codegen#1560
Conversation
Pull uu_ls's full clap argument definition into bashkit so scripts get
the same flag set, abbreviations, and validation as GNU coreutils,
while bashkit's existing rendering pipeline keeps emitting the bytes
it always did. Flags accepted by uu_ls but not yet implemented return
an explicit "not yet implemented" diagnostic (same pattern used by
tac -b/-r/-s) instead of silently producing wrong output.
Codegen-tool upgrades needed for ls:
- Sibling-file mod-options lookup: ls's options module lives in
config.rs, not ls.rs. find_mod_in_sibling_files() falls back to
scanning every .rs in the util's src/ directory before bailing.
- Nested submodules in mod options (options::format::COLUMNS,
options::sort::TIME, etc.) emit verbatim and resolve via the new
conditional 'use options::*;' glob in the generated preamble.
- ShortcutValueParser::new(...) → clap::builder::PossibleValuesParser::new(...).
uucore's unambiguous-abbreviation behaviour is dropped in favour of
exact-match clap semantics; documented divergence in the spec.
- Generated preamble now imports the broader clap::builder surface
(PossibleValue, PossibleValuesParser, NonEmptyStringValueParser).
- Cargo.toml: enable clap's 'env' feature for Arg::env("TIME_STYLE").
ls.rs now calls ls_command().try_get_matches_from() and reads the 8
short flags it already implemented (-l -a -h -1 -R -t -F -C). Any
other flag that clap parses triggers an early not-yet-implemented
exit. The existing rendering loop is untouched.
Spec tests in tests/spec_cases/bash/ls.test.sh cover -Q,
--quoting-style=, --group-directories-first, an unsupported short
flag inside a composite (-lr), the unknown-flag path, and ls --version.
Release-build size delta on bashkit-cli: 24,331,072 → 24,472,000 bytes
(+138 KB), driven by clap's env-feature + the 949-line generated file.
Closes #1531
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 2c988a9 | Commit Preview URL Branch Preview URL |
May 06 2026, 02:53 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pull
uu_ls's full clap argument definition into bashkit so scripts get the same flag set, abbreviations, and validation as GNU coreutils, while bashkit's existing rendering pipeline keeps emitting the bytes it always did. Flags accepted byuu_lsbut not yet implemented return an explicit "not yet implemented" diagnostic (same pattern used bytac -b/-r/-s) instead of silently producing wrong output.Why
Closes #1531.
crates/bashkit/src/builtins/ls.rspreviously parsed only 8 short flags (-l -a -h -1 -R -t -F -C) by hand and rejected everything else asinvalid option. Scripts that called common GNU-ls flags (-Q,--quoting-style=,--group-directories-first,--reverse, etc.) hit a confusing parse-error path. With this PR, the clap surface matches uutils' and unimplemented flags get a deterministic "not yet implemented" message that names the offending flag.How
Codegen-tool upgrades (
bashkit-coreutils-port)ls's structure broke three implicit assumptions in the existing tool:
mod optionslookup.ls's options module lives inconfig.rs, notls.rs. Newfind_mod_in_sibling_files()falls back to scanning every.rsin the util'ssrc/directory before bailing.options::format::COLUMNS,options::sort::TIME,options::indicator_style::CLASSIFY, …) — emit verbatim and resolve via a new conditionaluse options::*;glob in the generated preamble. Bare-name-const utils (mktemp, realpath, …) are unaffected because the glob is skipped when there's nomod options.ShortcutValueParser(uucore-internal type) — substituted withclap::builder::PossibleValuesParser::new(...). Loses uutils' unambiguous-abbreviation behaviour in exchange for clap's exact-match semantics (documented divergence in the spec; out-of-scope per Port ls argument surface from uutils via codegen #1531's "Out of scope" section).Generated preamble now imports the broader
clap::buildersurface (PossibleValue,PossibleValuesParser,NonEmptyStringValueParser). The change is benign for the previously-ported utils — they re-generate identically modulo the new imports (silenced by#![allow(unused_imports)]).Cargo.toml: enable clap'senvfeature soArg::env("TIME_STYLE")from uu_ls compiles.ls.rsmigrationSwitches argument parsing to
ls_command().try_get_matches_from(). The existing rendering loop is untouched. The 8 already-implemented flags are read offmatches. Every other ID that clap saw a non-default value for hits a singlenot yet implementedbranch:-F/--classifycarries an optionalalways|auto|nevervalue — treated as on foralways/auto/missing, off fornever.GNU help layout (
Usage:first) re-applied via the same.help_template(...)chaincat.rsandtac.rsuse.Tests
crates/bashkit/tests/spec_cases/bash/ls.test.shaddsls_quote_name_short_flag(-Q),ls_quoting_style_long_flag(--quoting-style=shell),ls_group_directories_first_flag,ls_composite_unsupported_then_supported(-lr),ls_unknown_flag_rejected, andls_version. Each### bash_diff-annotates the GNU divergence per AGENTS.md.builtins::ls::*lib tests pass;test_ls_invalid_optionupdated for clap's "unexpected argument" wording.bash_spec_testsintegration suite passes.Binary size delta
cargo build -p bashkit-cli --release:Driven by clap's
envfeature + the 949-line generatedls_args.rs(full 80+ flag definition compiled into the binary). Reasonable for a fully-wired uutils argument surface and well below the cat/tac POC's "+9 KB declared-but-unused" baseline projection scaled to ls's flag count.Out of scope (per #1531)
uu_lsoption (--context,--si,--block-size, full coloration). They stay parser-accepted with the explicit "not yet implemented" error.uucore::quoting-stylefor--quoting-stylesemantics — separate question, see the module-vendor mode issue (Add module-vendor mode to bashkit-coreutils-port #1533).ShortcutValueParsersemantics — see codegen substitution note above.coreutils-args-drift.ymlwill pick upls_argsautomatically via the existingpub mod ls_args;line — no workflow edit required.Pre-PR
cargo fmt --check✅cargo clippy -p bashkit --features http_client --all-targets -- -D warnings✅cargo test -p bashkit --features http_client --lib— 2264 pass, 0 fail ✅cargo test -p bashkit --features http_client --test spec_tests bash_spec_tests✅no_debug_fmt_in_builtin_source) passes — no{:?}in builtin source.Generated by Claude Code