Add ability to generate shell completions
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -74,6 +74,15 @@ dependencies = [
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19c9f1dde76b736e3681f28cec9d5a61299cbaae0fce80a68e43724ad56031eb"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.6.0"
|
||||
@@ -155,9 +164,10 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "pallet"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"colored",
|
||||
"glob",
|
||||
"serde",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
[package]
|
||||
name = "pallet"
|
||||
version = "1.0.2"
|
||||
version = "1.0.3"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.6.0", features = ["derive"] }
|
||||
clap_complete = "4.6.0"
|
||||
colored = "3.1.1"
|
||||
glob = "0.3.3"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
||||
2
PKGBUILD
2
PKGBUILD
@@ -1,6 +1,6 @@
|
||||
# Maintainer: Shea Frembling <sfrembling@gmail.com>
|
||||
pkgname=pallet
|
||||
pkgver=1.0.2
|
||||
pkgver=1.0.3
|
||||
pkgrel=1
|
||||
pkgdesc="A simple C project manager inspired by Cargo"
|
||||
arch=('x86_64')
|
||||
|
||||
55
src/app.rs
55
src/app.rs
@@ -4,6 +4,7 @@ use std::{
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use clap::CommandFactory;
|
||||
use colored::Colorize;
|
||||
use glob::glob;
|
||||
|
||||
@@ -41,6 +42,28 @@ enum Subcommand {
|
||||
},
|
||||
/// Clean all in progress files
|
||||
Clean,
|
||||
/// Utility functions
|
||||
Utils {
|
||||
#[clap(subcommand)]
|
||||
command: UtilSubcommand,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand)]
|
||||
enum UtilSubcommand {
|
||||
/// Generate shell completions
|
||||
Completions {
|
||||
/// The shell to generate completions for
|
||||
shell: ShellCompletions,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, clap::ValueEnum)]
|
||||
enum ShellCompletions {
|
||||
Bash,
|
||||
Fish,
|
||||
PowerShell,
|
||||
Zsh,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -87,6 +110,38 @@ impl App {
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Subcommand::Utils { command } => match command {
|
||||
UtilSubcommand::Completions { shell } => {
|
||||
let name = env!("CARGO_PKG_NAME");
|
||||
let mut command = App::command();
|
||||
match shell {
|
||||
ShellCompletions::Bash => clap_complete::generate(
|
||||
clap_complete::shells::Bash,
|
||||
&mut command,
|
||||
name,
|
||||
&mut std::io::stdout(),
|
||||
),
|
||||
ShellCompletions::Fish => clap_complete::generate(
|
||||
clap_complete::shells::Fish,
|
||||
&mut command,
|
||||
name,
|
||||
&mut std::io::stdout(),
|
||||
),
|
||||
ShellCompletions::PowerShell => clap_complete::generate(
|
||||
clap_complete::shells::PowerShell,
|
||||
&mut command,
|
||||
name,
|
||||
&mut std::io::stdout(),
|
||||
),
|
||||
ShellCompletions::Zsh => clap_complete::generate(
|
||||
clap_complete::shells::Zsh,
|
||||
&mut command,
|
||||
name,
|
||||
&mut std::io::stdout(),
|
||||
),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user