Skip to content

Commit

Permalink
feat: Add nushell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder committed Jan 5, 2025
1 parent bf462da commit 4c7e778
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ blue-build-utils = { version = "=0.9.1", path = "./utils" }
blue-build-process-management = { version = "=0.9.1", path = "./process" }
clap-verbosity-flag = "3"
clap_complete = "4"
clap_complete_nushell = "4"
fuzzy-matcher = "0.3"
jsonschema = { version = "0.28", optional = true }
open = "5"
Expand Down
7 changes: 5 additions & 2 deletions src/commands/completions.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use clap::{Args, CommandFactory};
use clap_complete::{generate, Shell as CompletionShell};
use clap_complete::generate;
use miette::Result;
use shells::Shells;

use crate::commands::BlueBuildArgs;

use super::BlueBuildCommand;

mod shells;

#[derive(Debug, Clone, Args)]
pub struct CompletionsCommand {
#[arg(value_enum)]
shell: CompletionShell,
shell: Shells,
}

impl BlueBuildCommand for CompletionsCommand {
Expand Down
52 changes: 52 additions & 0 deletions src/commands/completions/shells.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use clap::ValueEnum;
use clap_complete::{Generator, Shell as CompletionShell};
use clap_complete_nushell::Nushell;

#[derive(Debug, Clone, Copy, ValueEnum, PartialEq, Eq, Hash)]
pub enum Shells {
/// Bourne Again `SHell` (bash)
Bash,
/// Elvish shell
Elvish,
/// Friendly Interactive `SHell` (fish)
Fish,
/// `PowerShell`
PowerShell,
/// Z `SHell` (zsh)
Zsh,
/// Nushell (nu)
Nushell,
}

impl Generator for Shells {
fn file_name(&self, name: &str) -> String {
match *self {
Self::Bash => CompletionShell::Bash.file_name(name),
Self::Elvish => CompletionShell::Elvish.file_name(name),
Self::Fish => CompletionShell::Fish.file_name(name),
Self::PowerShell => CompletionShell::PowerShell.file_name(name),
Self::Zsh => CompletionShell::Zsh.file_name(name),
Self::Nushell => Nushell.file_name(name),
}
}

fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
match *self {
Self::Bash => CompletionShell::Bash.generate(cmd, buf),
Self::Elvish => CompletionShell::Elvish.generate(cmd, buf),
Self::Fish => CompletionShell::Fish.generate(cmd, buf),
Self::PowerShell => CompletionShell::PowerShell.generate(cmd, buf),
Self::Zsh => CompletionShell::Zsh.generate(cmd, buf),
Self::Nushell => Nushell.generate(cmd, buf),
}
}
}

impl std::fmt::Display for Shells {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}

0 comments on commit 4c7e778

Please sign in to comment.