diff --git a/Cargo.lock b/Cargo.lock index 65e9428..8e3b37c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11611dca53440593f38e6b25ec629de50b14cdfa63adc0fb856115a2c6d97595" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.5.18" @@ -174,6 +183,7 @@ name = "disk-read-benchmark" version = "0.2.0" dependencies = [ "clap", + "clap_complete", "csv", "curl", "rand", diff --git a/Cargo.toml b/Cargo.toml index ed4f949..1b5ae60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] clap = { version = "4.5.20", features = ["cargo", "derive"] } +clap_complete = "4.5.37" csv = "1.3.0" curl = "0.4.47" rand = "0.8.5" diff --git a/src/cli.rs b/src/cli.rs index a259f92..0ffe512 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,7 +8,14 @@ pub struct Cli { } #[derive(Subcommand)] +#[derive(Debug)] pub enum Commands { + ///Generate bash completions + GenerateBashCompletions, + ///Generate zsh completions + GenerateZshCompletions, + ///Generate fish completions + GenerateFishCompletions, ///Grabs the datasets used for benchmarking GrabData, ///Runs the benchmark diff --git a/src/lib.rs b/src/lib.rs index 98135b1..d63cbd0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ -pub mod dataset_gathering; pub mod benchmarks; -pub mod cli; \ No newline at end of file +pub mod cli; +pub mod dataset_gathering; diff --git a/src/main.rs b/src/main.rs index 1a3dd29..704c91c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ -use clap::Parser; +use clap::{CommandFactory, Parser}; +use clap_complete::aot::{generate, Bash, Fish, Zsh}; use disk_read_benchmark::benchmarks::benchmark; use disk_read_benchmark::cli::*; use disk_read_benchmark::dataset_gathering::*; +use std::io::stdout; fn main() { let cli = Cli::parse(); @@ -22,5 +24,30 @@ fn main() { grab_datasets().unwrap(); // * should unwrap benchmark(); } + // I can't be bothered to do this how I *should*, rather than hardcoding it + Commands::GenerateBashCompletions => { + generate( + Bash, + &mut Cli::command(), + "disk-read-benchmark", + &mut stdout(), + ); + } + Commands::GenerateZshCompletions => { + generate( + Zsh, + &mut Cli::command(), + "disk-read-benchmark", + &mut stdout(), + ); + } + Commands::GenerateFishCompletions => { + generate( + Fish, + &mut Cli::command(), + "disk-read-benchmark", + &mut stdout(), + ); + } } }