Add Fig completion support

i18n
Michal S 2 years ago committed by Michal
parent f04f8012a4
commit a3908ad8c3

11
Cargo.lock generated

@ -13,6 +13,7 @@ dependencies = [
"chrono", "chrono",
"clap", "clap",
"clap_complete", "clap_complete",
"clap_complete_fig",
"color-eyre", "color-eyre",
"colored", "colored",
"console", "console",
@ -249,6 +250,16 @@ dependencies = [
"clap", "clap",
] ]
[[package]]
name = "clap_complete_fig"
version = "3.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed37b4c0c1214673eba6ad8ea31666626bf72be98ffb323067d973c48b4964b9"
dependencies = [
"clap",
"clap_complete",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.2.18" version = "3.2.18"

@ -45,6 +45,7 @@ textwrap = "0.15.0"
crossterm = "0.25.0" crossterm = "0.25.0"
toml = "0.5.9" toml = "0.5.9"
clap_complete = "3.2.4" clap_complete = "3.2.4"
clap_complete_fig = "3.2.4"
color-eyre = { version = "0.6.2", features = ["issue-url", "url"] } color-eyre = { version = "0.6.2", features = ["issue-url", "url"] }
indicatif = { version = "0.17.0", features = ["tokio"] } indicatif = { version = "0.17.0", features = ["tokio"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"

@ -125,7 +125,7 @@ pub struct UpgradeArgs {
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct GenCompArgs { pub struct GenCompArgs {
/// The shell to generate completions for (bash, fish, elvish, pwsh) /// The shell to generate completions for (bash, fish, elvish, pwsh, fig)
#[clap(required = true)] #[clap(required = true)]
pub shell: String, pub shell: String,
} }

@ -13,6 +13,8 @@ use crate::logging::get_logger;
use crate::logging::Printable; use crate::logging::Printable;
use clap_complete::{Generator, Shell}; use clap_complete::{Generator, Shell};
use clap_complete_fig::Fig;
use std::str::FromStr; use std::str::FromStr;
mod args; mod args;
@ -200,19 +202,28 @@ async fn cmd_query(args: QueryArgs) {
#[tracing::instrument(level = "trace")] #[tracing::instrument(level = "trace")]
fn cmd_gencomp(args: &GenCompArgs) { fn cmd_gencomp(args: &GenCompArgs) {
let shell: Shell = Shell::from_str(&args.shell).unwrap_or_else(|e| { if args.shell == "fig" {
crash!(AppExitCode::Other, "Invalid shell: {}", e); clap_complete::generate(
}); Fig,
&mut <args::Args as clap::CommandFactory>::command(),
if shell == Shell::Zsh { "ame",
crash!( &mut std::io::stderr(),
AppExitCode::Other,
"Zsh shell completions are currently unsupported due to a bug in the clap_completion crate"
); );
}; } else {
let shell: Shell = Shell::from_str(&args.shell).unwrap_or_else(|e| {
crash!(AppExitCode::Other, "Invalid shell, {}", e);
});
shell.generate( if shell == Shell::Zsh {
&<args::Args as clap::CommandFactory>::command(), crash!(
&mut std::io::stderr(), AppExitCode::Other,
); "Zsh shell completions are currently unsupported due to a bug in the clap_completion crate"
);
};
shell.generate(
&<args::Args as clap::CommandFactory>::command(),
&mut std::io::stderr(),
);
}
} }

Loading…
Cancel
Save