From 58dbbbc0fc9cd01bc9ab234ef83ccabb2cdd0ca9 Mon Sep 17 00:00:00 2001 From: Muhammad Sadiq Date: Sat, 28 Nov 2026 22:58:10 +0500 Subject: [PATCH] Add Nushell completion support proofline completions already generates scripts for zsh, bash, fish, powershell and elvish via clap_complete::Shell. Nushell has no built-in generator in that crate, so add a CliShell wrapper enum that extends clap's ValueEnum with a Nushell variant backed by clap_complete_nushell, and dispatch to it in completions(). --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + README.md | 2 +- src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++----- tests/completions.rs | 1 + 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da34581..c1431d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,6 +320,16 @@ dependencies = [ "clap", ] +[[package]] +name = "clap_complete_nushell" +version = "4.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2572c7b66e6c875ce4f4b57b852a3238e3f6dadd209798c714d9408a4f892131" +dependencies = [ + "clap", + "clap_complete", +] + [[package]] name = "clap_derive" version = "4.6.7" @@ -1438,6 +1448,7 @@ dependencies = [ "axum", "clap", "clap_complete", + "clap_complete_nushell", "dbus-secret-service-keyring-store", "flate2", "jsonschema", diff --git a/Cargo.toml b/Cargo.toml index ab28092..39e45f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ path = "src/main.rs" anyhow = "1" clap = { version = "4", features = ["derive", "env"] } clap_complete = "4" +clap_complete_nushell = "4" flate2 = "1" sha2 = "0.10" tar = "0.4" diff --git a/README.md b/README.md index eea0165..95dbff3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ On Linux and macOS, install the CLI with `curl -fsSL https://proofline.sh/cli | A coding agent can continue setup from its shell without an MCP restart. `proofline setup guide` prints the instructions and needs no sign-in. `proofline setup status` prints the current setup step, readiness and blockers, and `proofline setup candidates [--query NAME]` lists the repositories and deployments an answer may name. Both print the hosted MCP tool result as JSON and need `setup:write`, like `proofline config get`. The agent saves answers with the [configuration commands](#configuration). -`proofline completions SHELL` prints a completion script for `zsh`, `bash`, `fish`, `powershell`, or `elvish` without signing in or making a network call. For example, add `source <(proofline completions zsh)` to `~/.zshrc`. +`proofline completions SHELL` prints a completion script for `zsh`, `bash`, `fish`, `powershell`, `elvish`, or `nushell` without signing in or making a network call. For example, add `source <(proofline completions zsh)` to `~/.zshrc`. ### Windows installation diff --git a/src/lib.rs b/src/lib.rs index 8c6f1d6..945a0e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,12 +143,14 @@ enum Command { /// /// For example, add `source <(proofline completions zsh)` to `~/.zshrc`, /// `proofline completions bash > ~/.local/share/bash-completion/completions/proofline`, - /// `proofline completions fish > ~/.config/fish/completions/proofline.fish`, or + /// `proofline completions fish > ~/.config/fish/completions/proofline.fish`, /// `proofline completions powershell | Out-String | Invoke-Expression` to a - /// PowerShell profile. + /// PowerShell profile, or `proofline completions nushell | save -f + /// ~/.cache/proofline/completions.nu` and `source` that file from Nushell's + /// `config.nu`. Completions { /// The shell to complete for. - shell: clap_complete::Shell, + shell: CliShell, }, /// Install the newest official release over this installer-managed binary. Update, @@ -183,6 +185,35 @@ enum Command { Hook(hooks::HookArgs), } +/// A shell that `completions` can print a script for: one of +/// [`clap_complete::Shell`]'s built-in generators, or Nushell, which `clap` +/// does not ship a generator for. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum CliShell { + Builtin(clap_complete::Shell), + Nushell, +} + +impl clap::ValueEnum for CliShell { + fn value_variants<'a>() -> &'a [Self] { + &[ + Self::Builtin(clap_complete::Shell::Bash), + Self::Builtin(clap_complete::Shell::Elvish), + Self::Builtin(clap_complete::Shell::Fish), + Self::Builtin(clap_complete::Shell::PowerShell), + Self::Builtin(clap_complete::Shell::Zsh), + Self::Nushell, + ] + } + + fn to_possible_value(&self) -> Option { + match self { + Self::Builtin(shell) => shell.to_possible_value(), + Self::Nushell => Some(clap::builder::PossibleValue::new("nushell")), + } + } +} + #[derive(Debug, Subcommand)] enum CiCommand { /// Wait for the pull-request review of the commit under test and report it. @@ -667,7 +698,7 @@ async fn connect( /// Writes the completion script for `shell`. It needs no origin, token or /// network, so it works before `proofline login`. -fn completions(shell: clap_complete::Shell, out: &mut dyn std::io::Write) -> anyhow::Result<()> { +fn completions(shell: CliShell, out: &mut dyn std::io::Write) -> anyhow::Result<()> { const NAME: &str = "proofline"; let full = ::command(); // The static generators offer hidden subcommands too, so leave them out. @@ -680,7 +711,12 @@ fn completions(shell: clap_complete::Shell, out: &mut dyn std::io::Write) -> any .filter(|subcommand| !subcommand.is_hide_set()) .cloned() .fold(command, clap::Command::subcommand); - clap_complete::generate(shell, &mut command, NAME, out); + match shell { + CliShell::Builtin(shell) => clap_complete::generate(shell, &mut command, NAME, out), + CliShell::Nushell => { + clap_complete::generate(clap_complete_nushell::Nushell, &mut command, NAME, out); + } + } out.flush()?; Ok(()) } diff --git a/tests/completions.rs b/tests/completions.rs index 733bd04..f021c34 100644 --- a/tests/completions.rs +++ b/tests/completions.rs @@ -19,6 +19,7 @@ fn every_shell_gets_a_script_naming_the_visible_commands() { ("bash", "complete -F _proofline"), ("fish", "complete -c proofline"), ("powershell", "Register-ArgumentCompleter"), + ("nushell", "module completions {"), ] { let output = completions(shell); assert!(output.status.success(), "{shell}: {output:?}");