-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💲 Add shell completions, improve README
- Loading branch information
1 parent
adeca62
commit 0ce60bb
Showing
5 changed files
with
52 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use clap::{Arg, ArgAction, ArgMatches, Command}; | ||
use clap_complete::Shell; | ||
use std::{io, process::ExitCode}; | ||
|
||
pub fn cmd() -> Command { | ||
Command::new("completions") | ||
.about("Generate shell completions") | ||
.arg( | ||
Arg::new("shell") | ||
.help("The shell for which to generate completions") | ||
.required(true) | ||
.value_parser(clap::value_parser!(Shell)), | ||
) | ||
} | ||
|
||
pub fn run(matches: &ArgMatches) -> ExitCode { | ||
let generator = matches.get_one::<Shell>("shell").copied().unwrap(); | ||
let mut command = super::cmd(); | ||
print_completions(generator, &mut command); | ||
|
||
ExitCode::SUCCESS | ||
} | ||
|
||
fn print_completions<G: clap_complete::Generator>(gen: G, cmd: &mut Command) { | ||
clap_complete::generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); | ||
} |
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