-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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_complete: always fail to generate into a tempfile #5372
Comments
FYI I just tried this with v3 and I got the same result: #!/usr/bin/env nargo
---
[dependencies]
clap = "3"
clap_complete = "3"
tempfile = "3.10.0"
---
use std::io::{Read, Write};
use clap::{Arg, ArgAction, Command};
fn main() {
let mut app = app();
println!("——————————————————————— Complete to stdout");
clap_complete::generate(
clap_complete::shells::Bash,
&mut app,
"just",
&mut std::io::stdout(),
);
println!("——————————————————————— DONE");
println!("——————————————————————— Complete to file");
let mut file = tempfile::tempfile().unwrap();
file.write_all(b"").unwrap(); // Try with file creation ?
clap_complete::generate(clap_complete::shells::Bash, &mut app, "just", &mut file);
file.flush().unwrap(); // Try with flushing ?
let mut buffer = String::new();
file.read_to_string(&mut buffer).unwrap();
println!("{buffer}");
println!("——————————————————————— DONE");
}
fn app() -> Command<'static> {
Command::new(env!("CARGO_PKG_NAME")).arg(
Arg::new("check")
.long("check")
.action(ArgAction::SetTrue)
.help("Help for checl"),
)
} I even made it independent of clap
and I still got no output. |
I tried with |
Found the bug, it's not clap-complete or tempfile, it's me being bad at files: I need to use |
Please complete the following tasks
Rust Version
rustc 1.76.0 (07dca489a 2024-02-04)
Clap Version
4.5.1
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run
produces:Details
Actual Behaviour
stdout
worksfile
does not worksExpected Behaviour
Both should work
Additional Context
Found while upgrading
just
toclap 4
in casey/just#1924Debug Output
with both
clap
andclap_complete
indebug
:Details
The text was updated successfully, but these errors were encountered: