uutils / uutils/coreutils

fmt: clap causes information loss

Open
#6,353 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - fmt
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

$ cat << EOF > test.txt
> do
> not
> format
> these
> words
> =but
> =these
> =words
> =please
> EOF
$ ../gnu/src/fmt -p= test.txt 
do
not
format
these
words
=but these words please
$ cargo run -q fmt -p= test.txt 
do not format these words =but =these =words =please
$

Or in general: GNU parses -p=ANYTHING to be the prefix =ANYTHING, whereas clap parses the same argument as the different string ANYTHING. This cannot be easily recovered, and basically requires parsing the arguments from scratch again.

This also affects many other tools. I think it was already documented somewhere, but I couldn't find it.

I see this as yet another strong argument in favor of #4254.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy with cargo run -q fmt -p= test.txt and compare it with GNU fmt using the example in the issue. Trace how fmt receives -p=ANYTHING through clap, then identify the affected tools and existing coverage; done means preserving the GNU prefix semantics without losing the leading =.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.