Skip to content

join: accept separate -o field operands - #15408

Merged
cakebaker merged 1 commit into
uutils:mainfrom
Franklin-Qi:fix/15279-join-o-separate-fields
Nov 7, 2026
Merged

cakebaker merged 1 commit into
uutils:mainfrom
Franklin-Qi:fix/15279-join-o-separate-fields

Conversation

@Franklin-Qi

@Franklin-Qi Franklin-Qi commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GNU join accepts field specs as separate arguments after -o. Coalesce those tokens before clap so they are not treated as file operands.

Closes: #15279

Comment thread src/uu/join/src/join.rs

/// Merge separate `-o` field operands into one value so clap does not treat
/// them as file operands (`join -o 1.1 1.2 2.2 f1 f2`).
fn coalesce_o_fields(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.

I would use a (peekable) iterator instead of manually handling the index. Something like:

    let mut out = Vec::with_capacity(args.len());
    let mut iter = args.into_iter().peekable();

    while let Some(arg) = iter.next() {
        if arg != "-o" {
            out.push(arg);
            continue;
        }

        out.push(arg);

        // if there is at least one o-field, consume and join them
        if let Some(mut joined) = iter.next_if(|f| looks_like_o_field(f)) {
            while let Some(field) = iter.next_if(|f| looks_like_o_field(f)) {
                joined.push(" ");
                joined.push(field);
            }
            out.push(joined);
        }
    }
    out
}

@cakebaker
cakebaker force-pushed the fix/15279-join-o-separate-fields branch from 7456e09 to e5ae437 Compare November 6, 2026 15:30
GNU join treats consecutive field tokens after -o as part of the format
list. Coalesce them before clap so they are not mistaken for file
operands.

Closes: uutils#15279
@cakebaker
cakebaker force-pushed the fix/15279-join-o-separate-fields branch from e5ae437 to 6fba991 Compare November 7, 2026 06:53
@cakebaker
cakebaker merged commit d85ed9b into uutils:main Nov 7, 2026
99 of 100 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

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.

join: -o field list given as separate operands is rejected as extra operands

2 participants