Skip to content

od: keep filenames after optional width flags - #15430

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/od-optional-width
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/od-optional-width

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Apply the default width when -w or --width has no attached value, keeping the following filename as an operand. Preserve attached widths, combined short flags, and operands after --.

Closes #10725.

Comment thread src/uu/od/src/od.rs Outdated
}
}

// Clap otherwise consumes the next operand as the optional width value.

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.

--strings file has the same issue, no? could be a follow-up

Comment thread src/uu/od/src/od.rs Outdated
})
});
if long_width {
arg.push_str("=32");

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.

"32" is now duplicated with default_missing_value("32"), could you please use a const?

@limadog9
limadog9 force-pushed the fix/od-optional-width branch from 2463acf to 425c474 Compare October 17, 2026 13:03
@limadog9

Copy link
Copy Markdown
Contributor Author
  • Added shared constants for the defaults.
  • Fixed the same filename bug with --strings and added regression tests.

Comment thread src/uu/od/src/od.rs Outdated
.skip(1)
.take_while(|arg| arg.as_str() != "--")
{
let long_width = arg.starts_with("--w") && "--width".starts_with(arg.as_str());

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.

the hardcoded --w/--st prefixes will silently break if a new long option is added, could you resolve them from command like for the short flags?

in general, trying to do clap job is HARD

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.

Fixed in 23f2082. The lookup now uses the options and aliases declared on the clap Command. Exact names win, and a prefix gets a default only when it identifies one option. I added a regression test with a second --widths option so --wid stays ambiguous while --width still works.

Comment thread src/uu/od/src/od.rs Outdated
}

// Attach missing optional values so Clap keeps the next operand as a filename.
fn default_optional_value_args(args: &[String], command: &Command) -> Vec<String> {

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.

did you run the GNU od tests with this?
git clone https://github.com/coreutils/coreutils.git ../gnu
bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/od/od.pl

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.

Ran the requested build and tests/od/od.pl against GNU 9.12. It passed 20 of 26 cases on both this commit and the unmodified base. The same six quoting and overflow cases failed, with identical diagnostics and exit statuses. All seven companion GNU od shell tests passed.

@limadog9
limadog9 force-pushed the fix/od-optional-width branch from 425c474 to 23f2082 Compare November 19, 2026 22:30

This branch has not been deployed

No deployments
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.

od: -w option mistakens positional argument for value

2 participants