feat(cli): add nushell completions

This commit is contained in:
Amaan Qureshi 2024-12-10 19:35:58 -05:00 committed by GitHub
parent 69d977d736
commit ea9aa018b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 7 deletions

11
Cargo.lock generated
View file

@ -240,6 +240,16 @@ dependencies = [
"clap",
]
[[package]]
name = "clap_complete_nushell"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "315902e790cc6e5ddd20cbd313c1d0d49db77f191e149f96397230fb82a17677"
dependencies = [
"clap",
"clap_complete",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
@ -1708,6 +1718,7 @@ dependencies = [
"bstr",
"clap",
"clap_complete",
"clap_complete_nushell",
"ctor",
"ctrlc",
"dialoguer",

View file

@ -105,6 +105,7 @@ clap = { version = "4.5.21", features = [
"unstable-styles",
] }
clap_complete = "4.5.38"
clap_complete_nushell = "4.5.4"
ctor = "0.2.9"
ctrlc = { version = "3.4.5", features = ["termination"] }
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }

View file

@ -33,6 +33,7 @@ anyhow.workspace = true
bstr.workspace = true
clap.workspace = true
clap_complete.workspace = true
clap_complete_nushell.workspace = true
ctor.workspace = true
ctrlc.workspace = true
dialoguer.workspace = true

View file

@ -7,7 +7,7 @@ use std::{
use anstyle::{AnsiColor, Color, Style};
use anyhow::{anyhow, Context, Result};
use clap::{crate_authors, Args, Command, FromArgMatches as _, Subcommand, ValueEnum};
use clap_complete::{generate, Shell};
use clap_complete::generate;
use dialoguer::{theme::ColorfulTheme, Confirm, FuzzySelect, Input};
use glob::glob;
use heck::ToUpperCamelCase;
@ -449,6 +449,16 @@ struct Complete {
pub shell: Shell,
}
#[derive(ValueEnum, Clone)]
pub enum Shell {
Bash,
Elvish,
Fish,
PowerShell,
Zsh,
Nushell,
}
impl InitConfig {
fn run() -> Result<()> {
if let Ok(Some(config_path)) = Config::find_config_file() {
@ -1293,12 +1303,19 @@ impl DumpLanguages {
impl Complete {
fn run(self, cli: &mut Command) {
generate(
self.shell,
cli,
cli.get_name().to_string(),
&mut std::io::stdout(),
);
let name = cli.get_name().to_string();
let mut stdout = std::io::stdout();
match self.shell {
Shell::Bash => generate(clap_complete::shells::Bash, cli, &name, &mut stdout),
Shell::Elvish => generate(clap_complete::shells::Elvish, cli, &name, &mut stdout),
Shell::Fish => generate(clap_complete::shells::Fish, cli, &name, &mut stdout),
Shell::PowerShell => {
generate(clap_complete::shells::PowerShell, cli, &name, &mut stdout);
}
Shell::Zsh => generate(clap_complete::shells::Zsh, cli, &name, &mut stdout),
Shell::Nushell => generate(clap_complete_nushell::Nushell, cli, &name, &mut stdout),
}
}
}