-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |