Skip to content

Commit 0a69a36

Browse files
authored
Merge pull request #137 from dupe-forks/main
add nushell completion gen support
2 parents 82a2fa1 + 3b88de9 commit 0a69a36

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ open = "5.1.4"
4343
rand = "0.9.2"
4444
tempfile = "3"
4545
dialoguer = "0.12.0"
46+
clap_complete_nushell = "4.5.10"
4647

4748
[target.'cfg(target_os = "android")'.dependencies]
4849
terminal-clipboard = "0.4.1"

src/cli.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::mod_file::PlatformName;
2+
use clap::{Command, ValueEnum};
3+
use clap_complete::Generator;
24

35
/// Command-line interface for Geode
46
#[derive(clap::Parser, Debug)]
@@ -8,6 +10,40 @@ pub struct Args {
810
pub command: GeodeCommands,
911
}
1012

13+
#[derive(Debug, ValueEnum, Clone)]
14+
pub enum Shell {
15+
Bash,
16+
Elvish,
17+
Fish,
18+
PowerShell,
19+
Zsh,
20+
Nushell,
21+
}
22+
23+
impl Generator for Shell {
24+
fn file_name(&self, name: &str) -> String {
25+
match self {
26+
Shell::Bash => format!("{}.bash", name),
27+
Shell::Elvish => format!("{}.elv", name),
28+
Shell::Fish => format!("{}.fish", name),
29+
Shell::PowerShell => format!("_{}.ps1", name),
30+
Shell::Zsh => format!("_{}", name),
31+
Shell::Nushell => clap_complete_nushell::Nushell.file_name(name),
32+
}
33+
}
34+
35+
fn generate(&self, cmd: &Command, buf: &mut dyn std::io::Write) {
36+
match self {
37+
Shell::Bash => clap_complete::shells::Bash.generate(cmd, buf),
38+
Shell::Elvish => clap_complete::shells::Elvish.generate(cmd, buf),
39+
Shell::Fish => clap_complete::shells::Fish.generate(cmd, buf),
40+
Shell::PowerShell => clap_complete::shells::PowerShell.generate(cmd, buf),
41+
Shell::Zsh => clap_complete::shells::Zsh.generate(cmd, buf),
42+
Shell::Nushell => clap_complete_nushell::Nushell.generate(cmd, buf),
43+
}
44+
}
45+
}
46+
1147
#[derive(clap::Subcommand, Debug)]
1248
pub enum GeodeCommands {
1349
/// Initialize a new Geode project
@@ -17,7 +53,7 @@ pub enum GeodeCommands {
1753
},
1854

1955
/// Generate shell completions and print it to stdout
20-
Completions { shell: clap_complete::Shell },
56+
Completions { shell: Shell },
2157

2258
/// Generate manpage and print it to stdout
2359
GenerateManpage {},

0 commit comments

Comments
 (0)