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",
"clap",
"clap_complete",
"clap_complete_fig",
"color-eyre",
"colored",
"console",
@ -249,6 +250,16 @@ dependencies = [
"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]]
name = "clap_derive"
version = "3.2.18"

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

@ -125,7 +125,7 @@ pub struct UpgradeArgs {
#[derive(Default, Debug, Clone, Parser)]
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)]
pub shell: String,
}

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