-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from schilkp/schilkp/autocomplete
cmd: add 'completion' command
- Loading branch information
Showing
9 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
// Copyright (c) 2017-2024 ETH Zurich | ||
// Philipp Schilk <[email protected]> | ||
|
||
//! The `completion` subcommand. | ||
use std::io; | ||
|
||
use crate::error::*; | ||
use clap::{builder::PossibleValue, Arg, ArgMatches, Command}; | ||
|
||
/// Assemble the `completion` subcommand. | ||
pub fn new() -> Command { | ||
Command::new("completion") | ||
.about("Emit shell completion script") | ||
.arg( | ||
Arg::new("completion_shell") | ||
.help("Shell completion script style") | ||
.required(true) | ||
.num_args(1) | ||
.value_name("SHELL") | ||
.value_parser([ | ||
PossibleValue::new("bash"), | ||
PossibleValue::new("elvish"), | ||
PossibleValue::new("fish"), | ||
PossibleValue::new("powershell"), | ||
PossibleValue::new("zsh"), | ||
]), | ||
) | ||
} | ||
|
||
/// Execute the `completion` subcommand. | ||
pub fn run(matches: &ArgMatches, app: &mut Command) -> Result<()> { | ||
let shell = matches.get_one::<String>("completion_shell").unwrap(); | ||
let shell = match shell.as_str() { | ||
"bash" => clap_complete::Shell::Bash, | ||
"elvish" => clap_complete::Shell::Elvish, | ||
"fish" => clap_complete::Shell::Fish, | ||
"powershell" => clap_complete::Shell::PowerShell, | ||
"zsh" => clap_complete::Shell::Zsh, | ||
_ => unreachable!(), | ||
}; | ||
clap_complete::generate(shell, app, "bender", &mut io::stdout()); | ||
Ok(()) | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
pub mod checkout; | ||
pub mod clone; | ||
pub mod completion; | ||
pub mod config; | ||
pub mod fusesoc; | ||
pub mod init; | ||
|
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