-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #570 - davidszotten:gen_completion_to, r=kbknapp
add `gen_completions_to` to write completions to buffer (e.g. stdout) instead of file. fixes #566 (for review; will fix commit message when done) still pretty new to rust so comments on anything from style to structure would be must appreciated!
- Loading branch information
Showing
4 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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 myapp"); | ||
} |