mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-13 17:35:37 +00:00
Add Nushell completion script generation support (#1756)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
+33
-1
@@ -3,7 +3,7 @@
|
||||
use std::io;
|
||||
|
||||
use clap::Command;
|
||||
use clap_complete::Generator;
|
||||
use clap_complete::{Generator, Shell};
|
||||
|
||||
mod arch;
|
||||
mod gateway;
|
||||
@@ -30,6 +30,38 @@ mod tests;
|
||||
pub const VERSION: &str = common::constants::EASYTIER_VERSION;
|
||||
rust_i18n::i18n!("locales", fallback = "en");
|
||||
|
||||
#[derive(clap::ValueEnum, Debug, Clone, PartialEq)]
|
||||
pub enum ShellType {
|
||||
Bash,
|
||||
Elvish,
|
||||
Fish,
|
||||
Powershell,
|
||||
Zsh,
|
||||
Nu,
|
||||
}
|
||||
|
||||
impl ShellType {
|
||||
pub fn to_shell(&self) -> Option<Shell> {
|
||||
match self {
|
||||
ShellType::Bash => Some(Shell::Bash),
|
||||
ShellType::Elvish => Some(Shell::Elvish),
|
||||
ShellType::Fish => Some(Shell::Fish),
|
||||
ShellType::Powershell => Some(Shell::PowerShell),
|
||||
ShellType::Zsh => Some(Shell::Zsh),
|
||||
ShellType::Nu => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_completions<G: Generator>(generator: G, cmd: &mut Command, bin_name: &str) {
|
||||
clap_complete::generate(generator, cmd, bin_name, &mut io::stdout());
|
||||
}
|
||||
|
||||
pub fn print_nushell_completions(cmd: &mut Command, bin_name: &str) {
|
||||
clap_complete::generate(
|
||||
clap_complete_nushell::Nushell,
|
||||
cmd,
|
||||
bin_name,
|
||||
&mut io::stdout(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user