Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] unintended behavior when using "-1" #1393

Closed
1 task done
borkd opened this issue Oct 3, 2023 · 1 comment · Fixed by #1394
Closed
1 task done

[BUG] unintended behavior when using "-1" #1393

borkd opened this issue Oct 3, 2023 · 1 comment · Fixed by #1394
Labels

Comments

@borkd
Copy link

borkd commented Oct 3, 2023

Checks

  • I have read the troubleshooting section and still think this is a bug.

Describe the bug you encountered:

Thanks for fd, it comes in handy!

Attempts to use the shorthand -1 alias instead of --max-results with exec or batch exec are not prevented, and the operations will be performed on every object which matches the query instead of the first hit. Depending on what one was trying to achieve the impact of this can be quite significant.

The alias does not have the relevant conflicts_with

fd/src/cli.rs

Lines 513 to 522 in 93cdb26

/// Limit the search to a single result and quit immediately.
/// This is an alias for '--max-results=1'.
#[arg(
short = '1',
hide_short_help = true,
overrides_with("max_results"),
help = "Limit search to a single result",
long_help
)]
max_one_result: bool,

Using long option --max-results=1 would yield immediate abort and explanation that options conflict:

fd/src/cli.rs

Lines 20 to 30 in 93cdb26

#[derive(Parser)]
#[command(
name = "fd",
version,
about = "A program to find entries in your filesystem",
after_long_help = "Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues",
max_term_width = 98,
args_override_self = true,
group(ArgGroup::new("execs").args(&["exec", "exec_batch", "list_details"]).conflicts_with_all(&[
"max_results", "has_results", "count"])),
)]

Finally -1 overrides_with --max-results, but not the other way around so fd --max-results=1 -1 -X prog query will launch prog against all objects matching query.

Describe what you expected to happen:

Consistent behavior: if mixing max-results with exec-type functions is refused, same should be true for aliases.

What version of fd are you using?

8.7.0

Which operating system / distribution are you on?

Linux
@borkd borkd added the bug label Oct 3, 2023
@emikitas
Copy link

emikitas commented Oct 4, 2023

Hi,
I can take this. I reproduced this bug and saw it doesn't reproduce in version 8.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants