diff --git a/Cargo.lock b/Cargo.lock index 6f81f92..7436b9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index cb773ad..f9dc473 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/PKGBUILD b/PKGBUILD index 869656c..dfa8517 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Shea Frembling pkgname=pallet -pkgver=1.0.2 +pkgver=1.0.3 pkgrel=1 pkgdesc="A simple C project manager inspired by Cargo" arch=('x86_64') diff --git a/src/app.rs b/src/app.rs index 66930bd..02c8f36 100644 --- a/src/app.rs +++ b/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(), + ), + } + } + }, } } }