mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
b1b16d56d8
With these options, in case the completion function cannot provide suggestions, Bash will perform its default completions, based on e.g. files, directories, and variable names. This is particularly useful for argument values.
25 lines
846 B
Rust
25 lines
846 B
Rust
extern crate clap;
|
|
|
|
use clap::{App, Arg, SubCommand, Shell};
|
|
|
|
#[test]
|
|
fn test_generation() {
|
|
let mut app = App::new("myapp")
|
|
.about("Tests completions")
|
|
.arg(Arg::with_name("file")
|
|
.help("some input file"))
|
|
.subcommand(SubCommand::with_name("test")
|
|
.about("tests things")
|
|
.arg(Arg::with_name("case")
|
|
.long("case")
|
|
.takes_value(true)
|
|
.help("the case to test")));
|
|
let mut buf = vec![];
|
|
app.gen_completions_to("myapp", Shell::Bash, &mut buf);
|
|
let string = String::from_utf8(buf).unwrap();
|
|
let first_line = string.lines().nth(0).unwrap();
|
|
let last_line = string.lines().rev().nth(0).unwrap();
|
|
|
|
assert_eq!(first_line, "_myapp() {");
|
|
assert_eq!(last_line, "complete -F _myapp -o bashdefault -o default myapp");
|
|
}
|