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

Clap-generated shell completion failing on macOS /bin/bash with: conditional binary operator expected: syntax error near `IFS' #5430

Closed
2 tasks done
gibfahn opened this issue Mar 26, 2024 · 3 comments · Fixed by #5444
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-medium Call for participation: Experience needed to fix: Medium / intermediate

Comments

@gibfahn
Copy link
Contributor

gibfahn commented Mar 26, 2024

Please complete the following tasks

Rust Version

rustc -V
rustc 1.77.0 (aedd173a2 2024-03-17)

Clap Version

4.5.3

Minimal reproducible code

# Cargo.toml
[package]
name = "my-app"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.3", features = [
  "debug",
  "derive",
  "env",
  "string",
  "wrap_help",
] }
clap_complete = "=4.5.1"
// src/main.rs
use clap::{CommandFactory, Parser, ValueHint};
use clap_complete::{generate, Shell};
use std::path::PathBuf;

#[derive(Parser)]
struct Opt {
    #[arg(short, long, value_hint = ValueHint::FilePath)]
    file: Option<PathBuf>,
}

fn main() {
    generate(
        Shell::Bash,
        &mut Opt::command(),
        "my-app",
        &mut std::io::stdout(),
    );
}

Steps to reproduce the bug with the above code

(on a Mac)

cargo run | /bin/bash

Actual Behaviour

Output:

cargo run | /bin/bash
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/my-app`
/bin/bash: line 30: conditional binary operator expected
/bin/bash: line 30: syntax error near `IFS'
/bin/bash: line 30: `                    if [[ -v IFS ]]; then'

Expected Behaviour

Output:

cargo run | /bin/bash
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/my-app`

Additional Context

On clap_complete 4.4.9 this works, on 4.4.10 this fails. I think that this is a regression introduced by #5336 . So the issue is probably the same as #5190 , which was fixed by #5278.

Debug Output

[clap_builder::builder::command]Command::_build: name="my-app"
[clap_builder::builder::command]Command::_propagate:my-app
[clap_builder::builder::command]Command::_check_help_and_version:my-app expand_help_tree=true
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_propagate_global_args:my-app
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:file
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:help
[clap_builder::builder::debug_asserts]Command::_verify_positionals
[clap_builder::builder::command]Command::_build_bin_names
[ clap_builder::output::usage]Usage::get_required_usage_from: incls=[], matcher=false, incl_last=true
[ clap_builder::output::usage]Usage::get_required_usage_from: unrolled_reqs=[]
[ clap_builder::output::usage]Usage::get_required_usage_from: ret_val=[]
@gibfahn gibfahn added the C-bug Category: Updating dependencies label Mar 26, 2024
@epage
Copy link
Member

epage commented Mar 26, 2024

This is happening too often and I'm tempted to say bash 4 is unsupported until #3166 is the default completion system since that at least reduces the risk we'll run into issues.

@epage epage added A-completion Area: completion generator E-medium Call for participation: Experience needed to fix: Medium / intermediate labels Mar 26, 2024
@sudotac
Copy link
Contributor

sudotac commented Apr 7, 2024

Sorry for the inconvenience.
I thought -v was already supported on bash 4.0, but actually only available on 5.0 or later.
I submitted #5444 to fix this. Feel free to use it.

This is happening too often and I'm tempted to say bash 4 is unsupported until #3166 is the default completion system since that at least reduces the risk we'll run into issues.

I agree with it.
This time it's easy to fix that, but caring about unsupported features on (very) older versions anytime is generally a hard work.

(By the way, I'm personally looking forward to native completion system!)

@gibfahn
Copy link
Contributor Author

gibfahn commented Apr 17, 2024

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants