add command completion generation

This commit is contained in:
askiiart 2024-11-12 11:22:42 -06:00
parent b78a37a8a4
commit 1d1a94b30e
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30
5 changed files with 48 additions and 3 deletions

10
Cargo.lock generated
View file

@ -94,6 +94,15 @@ dependencies = [
"strsim", "strsim",
] ]
[[package]]
name = "clap_complete"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11611dca53440593f38e6b25ec629de50b14cdfa63adc0fb856115a2c6d97595"
dependencies = [
"clap",
]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.18" version = "4.5.18"
@ -174,6 +183,7 @@ name = "disk-read-benchmark"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"clap", "clap",
"clap_complete",
"csv", "csv",
"curl", "curl",
"rand", "rand",

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "4.5.20", features = ["cargo", "derive"] } clap = { version = "4.5.20", features = ["cargo", "derive"] }
clap_complete = "4.5.37"
csv = "1.3.0" csv = "1.3.0"
curl = "0.4.47" curl = "0.4.47"
rand = "0.8.5" rand = "0.8.5"

View file

@ -8,7 +8,14 @@ pub struct Cli {
} }
#[derive(Subcommand)] #[derive(Subcommand)]
#[derive(Debug)]
pub enum Commands { pub enum Commands {
///Generate bash completions
GenerateBashCompletions,
///Generate zsh completions
GenerateZshCompletions,
///Generate fish completions
GenerateFishCompletions,
///Grabs the datasets used for benchmarking ///Grabs the datasets used for benchmarking
GrabData, GrabData,
///Runs the benchmark ///Runs the benchmark

View file

@ -1,3 +1,3 @@
pub mod dataset_gathering;
pub mod benchmarks; pub mod benchmarks;
pub mod cli; pub mod cli;
pub mod dataset_gathering;

View file

@ -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::benchmarks::benchmark;
use disk_read_benchmark::cli::*; use disk_read_benchmark::cli::*;
use disk_read_benchmark::dataset_gathering::*; use disk_read_benchmark::dataset_gathering::*;
use std::io::stdout;
fn main() { fn main() {
let cli = Cli::parse(); let cli = Cli::parse();
@ -22,5 +24,30 @@ fn main() {
grab_datasets().unwrap(); // * should unwrap grab_datasets().unwrap(); // * should unwrap
benchmark(); 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(),
);
}
} }
} }