Skip to content

Commit

Permalink
Add Carapace
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaals committed Mar 10, 2023
1 parent 7bc31ef commit b49900b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ categories = ["command-line-interface"]

[features]
default = ["fig", "nushell"]
carapace = ["dep:carapace_spec_clap"]
fig = ["dep:clap_complete_fig"]
nushell = ["dep:clap_complete_nushell"]

[dependencies]
clap = "4"
clap_complete = "4"

carapace_spec_clap = { version = "0.1", optional = true }
clap_complete_fig = { version = "4", optional = true }
clap_complete_nushell = { version = "0.1", optional = true }

Expand Down
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ use clap::ValueEnum;
pub enum Shell {
/// Bourne Again SHell (bash)
Bash,
/// Carapace spec
#[cfg(feature = "carapace")]
Carapace,
/// Elvish shell
Elvish,
/// Fig
Expand All @@ -210,6 +213,8 @@ impl clap_complete::Generator for Shell {
Self::PowerShell => clap_complete::Shell::PowerShell.file_name(name),
Self::Zsh => clap_complete::Shell::Zsh.file_name(name),

#[cfg(feature = "carapace")]
Self::Carapace => carapace_spec_clap::Spec.file_name(name),
#[cfg(feature = "fig")]
Self::Fig => clap_complete_fig::Fig.file_name(name),
#[cfg(feature = "nushell")]
Expand All @@ -225,6 +230,8 @@ impl clap_complete::Generator for Shell {
Self::PowerShell => clap_complete::Shell::PowerShell.generate(cmd, buf),
Self::Zsh => clap_complete::Shell::Zsh.generate(cmd, buf),

#[cfg(feature = "carapace")]
Self::Carapace => carapace_spec_clap::Spec.generate(cmd, buf),
#[cfg(feature = "fig")]
Self::Fig => clap_complete_fig::Fig.generate(cmd, buf),
#[cfg(feature = "nushell")]
Expand Down Expand Up @@ -271,6 +278,8 @@ impl ValueEnum for Shell {
fn value_variants<'a>() -> &'a [Self] {
&[
Self::Bash,
#[cfg(feature = "carapace")]
Self::Carapace,
Self::Elvish,
#[cfg(feature = "fig")]
Self::Fig,
Expand All @@ -285,6 +294,8 @@ impl ValueEnum for Shell {
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
Some(match self {
Self::Bash => clap::builder::PossibleValue::new("bash"),
#[cfg(feature = "carapace")]
Self::Carapace => clap::builder::PossibleValue::new("carapace"),
Self::Elvish => clap::builder::PossibleValue::new("elvish"),
#[cfg(feature = "fig")]
Self::Fig => clap::builder::PossibleValue::new("fig"),
Expand All @@ -307,6 +318,14 @@ mod tests {
assert_eq!(Shell::Bash.to_possible_value().unwrap().get_name(), "bash");
}
#[test]
#[cfg(feature = "carapace")]
fn check_casing_carapace() {
assert_eq!(
Shell::Carapace.to_possible_value().unwrap().get_name(),
"carapace"
);
}
#[test]
fn check_casing_elvish() {
assert_eq!(
Shell::Elvish.to_possible_value().unwrap().get_name(),
Expand Down Expand Up @@ -353,6 +372,7 @@ mod tests {

let correct_order = [
("bash", true),
("carapace", cfg!(feature = "carapace")),
("elvish", true),
("fig", cfg!(feature = "fig")),
("fish", true),
Expand Down

0 comments on commit b49900b

Please sign in to comment.