Clap-generated shell completion failing on macOS /bin/bash with: conditional binary operator expected: syntax error near `IFS'
gibfahn opened this issue · comments
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
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=[]
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.
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!)
Thanks for fixing this!