Skip to content

cut: keep the '=' that follows a short option in its value - #16437

Closed
binhvq wants to merge 2 commits into
uutils:mainfrom
binhvq:cut-short-equals
Closed

binhvq wants to merge 2 commits into
uutils:mainfrom
binhvq:cut-short-equals

Conversation

@binhvq

@binhvq binhvq commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Closes #16436

GNU takes everything after a short option letter as its value, so -b=1 is the invalid list =1 and -O=x sets the output delimiter to =x. clap drops that =, and only -d= was special-cased. The rewrite now moves any =... value of -b, -c, -d, -f, -F and -O (also after -n/-s/-z in the same cluster) into its own argument, which clap keeps as is. Values given as the next argument, like -O -b=1, and operands after -- are not touched.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/usage_vs_getopt (passes in this run but fails in the 'main' branch)

Comment thread src/uu/cut/src/cut.rs Outdated
/// clap drops that `=`, see
/// <https://github.com/uutils/coreutils/issues/2424#issuecomment-863825242>.
/// Such a value is moved to its own argument, which clap keeps verbatim.
/// Arguments after `--`, and the value of an option given as the next

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 lines of comment, could you please make it shorter? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shortened to two lines.

Comment thread src/uu/cut/src/cut.rs Outdated
fn split_equals_values(args: Vec<OsString>) -> Vec<OsString> {
const FLAGS: &str = "nsz";
const SHORT_WITH_VALUE: &str = "bcdfFO";
const LONG_WITH_VALUE: [&str; 5] = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these lists will drift from uu_app(), could we derive them from its args instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, the short/long lists are now built from the Command's args (a value that is optional, like -w's, is left alone as before).

@codspeed

codspeed Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 20.31%

2 warnings, 1 note

⚠️ 122 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
✅ 404 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory cp_recursive_deep_tree[(120, 4)] 699.2 KB 581.2 KB +20.31%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing binhvq:cut-short-equals (c08c2e0) with main (dbbe8ff)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (18ddc48) during the generation of this report, so dbbe8ff was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

Comment thread src/uu/cut/src/cut.rs

/// GNU keeps the `=` in `-d=x` as part of the value but clap drops it, so such
/// a value is moved to its own argument, which clap keeps verbatim.
fn split_equals_values(command: &Command, args: Vec<OsString>) -> Vec<OsString> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are you sure there isnt a way to do that in clap ?
it s a long function :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked, but clap always drops the = after a short option (parse_short_arg in clap_builder), and there is no setting for it. Most of the length is the getopt-like scan, so that a value that looks like an option (-O -b=1) is left alone. If you prefer something short like fmt's preserve_prefix_equals, I can drop that case. Which would you like?

@binhvq

binhvq commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing this: I could not find a way to do it in clap, and the argv rewrite is too long for such a rare case. #16436 stays open in case someone sees a cleaner approach.

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.

cut: the '=' after a short option is dropped from its value

2 participants