Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 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 @@ -47,6 +47,7 @@ open = "5.1.4"
rand = "0.8.5"
tempfile = "3"
dialoguer = "0.11.0"
clap_complete_nushell = "4.5.6"

[target.'cfg(target_os = "android")'.dependencies]
terminal-clipboard = "0.4.1"
Expand Down
38 changes: 37 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::mod_file::PlatformName;
use clap::{Command, ValueEnum};
use clap_complete::Generator;

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

#[derive(Debug, ValueEnum, Clone)]
pub enum Shell {
Bash,
Elvish,
Fish,
PowerShell,
Zsh,
NuShell,
}

impl Generator for Shell {
fn file_name(&self, name: &str) -> String {
match self {
Shell::Bash => format!("{}.bash", name),
Shell::Elvish => format!("{}.elv", name),
Shell::Fish => format!("{}.fish", name),
Shell::PowerShell => format!("_{}.ps1", name),
Shell::Zsh => format!("_{}", name),
Shell::NuShell => clap_complete_nushell::Nushell.file_name(name),
}
}

fn generate(&self, cmd: &Command, buf: &mut dyn std::io::Write) {
match self {
Shell::Bash => clap_complete::shells::Bash.generate(cmd, buf),
Shell::Elvish => clap_complete::shells::Elvish.generate(cmd, buf),
Shell::Fish => clap_complete::shells::Fish.generate(cmd, buf),
Shell::PowerShell => clap_complete::shells::PowerShell.generate(cmd, buf),
Shell::Zsh => clap_complete::shells::Zsh.generate(cmd, buf),
Shell::NuShell => clap_complete_nushell::Nushell.generate(cmd, buf),
}
}
}

#[derive(clap::Subcommand, Debug)]
pub enum GeodeCommands {
/// Initialize a new Geode project
Expand All @@ -17,7 +53,7 @@ pub enum GeodeCommands {
},

/// Generate shell completions and print it to stdout
Completions { shell: clap_complete::Shell },
Completions { shell: Shell },

/// Generate manpage and print it to stdout
GenerateManpage {},
Expand Down