add cli
This commit is contained in:
parent
f77783c66f
commit
5b035fe12c
3 changed files with 55 additions and 32 deletions
|
@ -8,3 +8,6 @@ alphanumeric-sort = "1.5.3"
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
clap_complete = "4.5.40"
|
clap_complete = "4.5.40"
|
||||||
yaml-rust2 = "0.9.0"
|
yaml-rust2 = "0.9.0"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
|
37
src/cli.rs
37
src/cli.rs
|
@ -9,15 +9,40 @@ pub struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
///Generate bash completions
|
///Generate shell completions
|
||||||
GenerateBashCompletions,
|
GenCompletion {
|
||||||
///Generate zsh completions
|
#[command(subcommand)]
|
||||||
GenerateZshCompletions,
|
shell: ShellCommands,
|
||||||
///Generate fish completions
|
},
|
||||||
GenerateFishCompletions,
|
|
||||||
///Runs it
|
///Runs it
|
||||||
Run {
|
Run {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
config: String,
|
config: String,
|
||||||
|
#[arg(short, long)]
|
||||||
|
daemonize: bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug)]
|
||||||
|
pub enum ShellCommands {
|
||||||
|
Bash {
|
||||||
|
#[arg(short, long, default_value = "gregory")]
|
||||||
|
binary_name: String,
|
||||||
|
},
|
||||||
|
Zsh {
|
||||||
|
#[arg(short, long, default_value = "gregory")]
|
||||||
|
binary_name: String,
|
||||||
|
},
|
||||||
|
Fish {
|
||||||
|
#[arg(short, long, default_value = "gregory")]
|
||||||
|
binary_name: String,
|
||||||
|
},
|
||||||
|
Elvish {
|
||||||
|
#[arg(short, long, default_value = "gregory")]
|
||||||
|
binary_name: String,
|
||||||
|
},
|
||||||
|
PowerShell {
|
||||||
|
#[arg(short, long, default_value = "gregory")]
|
||||||
|
binary_name: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
47
src/main.rs
47
src/main.rs
|
@ -1,8 +1,7 @@
|
||||||
use crate::cli::Commands;
|
|
||||||
use crate::cli::*;
|
use crate::cli::*;
|
||||||
use alphanumeric_sort::sort_str_slice;
|
use alphanumeric_sort::sort_str_slice;
|
||||||
use clap::{CommandFactory, Parser};
|
use clap::{CommandFactory, Parser};
|
||||||
use clap_complete::aot::{generate, Bash, Fish, Zsh};
|
use clap_complete::aot::{generate, Bash, Elvish, Fish, PowerShell, Zsh};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
use yaml_rust2::YamlLoader;
|
use yaml_rust2::YamlLoader;
|
||||||
|
@ -13,31 +12,27 @@ fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::GenerateBashCompletions => {
|
Commands::GenCompletion { shell } => match shell {
|
||||||
generate(
|
ShellCommands::Bash { binary_name } => {
|
||||||
Bash,
|
generate(Bash, &mut Cli::command(), binary_name, &mut stdout());
|
||||||
&mut Cli::command(),
|
}
|
||||||
"gregory",
|
ShellCommands::Zsh { binary_name } => {
|
||||||
&mut stdout(),
|
generate(Zsh, &mut Cli::command(), binary_name, &mut stdout());
|
||||||
);
|
}
|
||||||
|
ShellCommands::Fish { binary_name } => {
|
||||||
|
generate(Fish, &mut Cli::command(), binary_name, &mut stdout());
|
||||||
|
}
|
||||||
|
ShellCommands::Elvish { binary_name } => {
|
||||||
|
generate(Elvish, &mut Cli::command(), binary_name, &mut stdout());
|
||||||
|
}
|
||||||
|
ShellCommands::PowerShell { binary_name } => {
|
||||||
|
generate(PowerShell, &mut Cli::command(), binary_name, &mut stdout());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Commands::Run { config, daemonize } => {
|
||||||
|
println!("{}", config);
|
||||||
|
println!("{}", daemonize)
|
||||||
}
|
}
|
||||||
Commands::GenerateZshCompletions => {
|
|
||||||
generate(
|
|
||||||
Zsh,
|
|
||||||
&mut Cli::command(),
|
|
||||||
"gregory",
|
|
||||||
&mut stdout(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Commands::GenerateFishCompletions => {
|
|
||||||
generate(
|
|
||||||
Fish,
|
|
||||||
&mut Cli::command(),
|
|
||||||
"gregory",
|
|
||||||
&mut stdout(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Commands::Run => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue