mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-28 09:27:44 +00:00
xtask: add completion generation
This commit is contained in:
parent
a341d08c45
commit
0e07241280
6 changed files with 147 additions and 17 deletions
69
xtask/main.rs
Normal file
69
xtask/main.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
use std::io;
|
||||
|
||||
use clap::{
|
||||
CommandFactory,
|
||||
Parser as _,
|
||||
};
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
struct Cli {
|
||||
#[clap(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand)]
|
||||
enum Command {
|
||||
/// Generate completions for the specified shell.
|
||||
GenerateCompletions {
|
||||
#[arg(long)]
|
||||
shell: Shell,
|
||||
|
||||
#[arg(long)]
|
||||
binary: Binary,
|
||||
},
|
||||
}
|
||||
|
||||
#[expect(clippy::enum_variant_names)]
|
||||
#[derive(clap::ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Shell {
|
||||
Bash,
|
||||
Elvish,
|
||||
Fish,
|
||||
PowerShell,
|
||||
Zsh,
|
||||
Nushell,
|
||||
}
|
||||
|
||||
#[derive(clap::ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Binary {
|
||||
Watt,
|
||||
Cpu,
|
||||
Power,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Command::GenerateCompletions { shell, binary } => {
|
||||
let mut command = match binary {
|
||||
Binary::Watt => watt::WattCommand::command(),
|
||||
Binary::Cpu => watt::CpuCommand::command(),
|
||||
Binary::Power => watt::PowerCommand::command(),
|
||||
};
|
||||
command.set_bin_name(format!("{binary:?}").to_lowercase());
|
||||
command.build();
|
||||
|
||||
let shell: &dyn clap_complete::Generator = match shell {
|
||||
Shell::Bash => &clap_complete::Shell::Bash,
|
||||
Shell::Elvish => &clap_complete::Shell::Elvish,
|
||||
Shell::Fish => &clap_complete::Shell::Fish,
|
||||
Shell::PowerShell => &clap_complete::Shell::PowerShell,
|
||||
Shell::Zsh => &clap_complete::Shell::Zsh,
|
||||
Shell::Nushell => &clap_complete_nushell::Nushell,
|
||||
};
|
||||
|
||||
shell.generate(&command, &mut io::stdout());
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue