From 3f1f974ec771ca954414114b01ac20d4ffb608c3 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 18 Jun 2024 13:07:31 -0400 Subject: [PATCH] feat: add `generate-completions` cmd., support Nushell --- Cargo.lock | 33 +++++++++++++++++++++++++++------ moz-webgpu-cts/Cargo.toml | 2 ++ moz-webgpu-cts/src/main.rs | 23 ++++++++++++++++++++++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 363fe85..7d29b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" dependencies = [ "clap_builder", "clap_derive", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" dependencies = [ "anstream", "anstyle", @@ -172,11 +172,30 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2020fa13af48afc65a9a87335bda648309ab3d154cd03c7ff95b378c7ed39c4" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_complete_nushell" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1accf1b463dee0d3ab2be72591dccdab8bef314958340447c882c4c72acfe2a3" +dependencies = [ + "clap", + "clap_complete", +] + [[package]] name = "clap_derive" -version = "4.5.4" +version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -589,6 +608,8 @@ version = "1.0.0" dependencies = [ "camino", "clap", + "clap_complete", + "clap_complete_nushell", "enum-map", "enumset", "env_logger", diff --git a/moz-webgpu-cts/Cargo.toml b/moz-webgpu-cts/Cargo.toml index f76b496..ec62d5e 100644 --- a/moz-webgpu-cts/Cargo.toml +++ b/moz-webgpu-cts/Cargo.toml @@ -32,6 +32,8 @@ thiserror = { workspace = true } wax = { version = "0.6.0", features = ["miette"], git = "https://github.com/ErichDonGubler/wax", branch = "static-miette-diags"} whippit = { version = "0.6.2", path = "../whippit", default-features = false, features = ["serde1"] } enum-map = { version = "2.7.3", features = ["serde"] } +clap_complete = "4.5.5" +clap_complete_nushell = "4.5.2" [dev-dependencies] insta = { workspace = true } diff --git a/moz-webgpu-cts/src/main.rs b/moz-webgpu-cts/src/main.rs index f3cd9c1..bd5e9f1 100644 --- a/moz-webgpu-cts/src/main.rs +++ b/moz-webgpu-cts/src/main.rs @@ -29,7 +29,7 @@ use std::{ use crate::wpt::path::Browser; use camino::Utf8PathBuf; -use clap::{Parser, ValueEnum}; +use clap::{CommandFactory, Parser, ValueEnum}; use enumset::{EnumSet, EnumSetType}; use format::lazy_format; use indexmap::{IndexMap, IndexSet}; @@ -110,6 +110,8 @@ enum Subcommand { /// Dump all metadata as JSON. Do so at your own risk; no guarantees are made about the /// schema of this JSON, for now. DumpJson, + /// Generate completions for various supported shells. + GenerateCompletions { shell: CompletionShell }, } #[derive(Clone, Debug, clap::Args)] @@ -271,6 +273,11 @@ enum UpdateBacklogSubcommand { }, } +#[derive(Clone, Copy, Debug, ValueEnum)] +enum CompletionShell { + Nushell, +} + fn main() -> ExitCode { env_logger::builder() .filter_level(log::LevelFilter::Info) @@ -1082,6 +1089,20 @@ fn run(cli: Cli) -> ExitCode { } } } + Subcommand::GenerateCompletions { shell } => { + let generator = match shell { + CompletionShell::Nushell => clap_complete_nushell::Nushell, + }; + + clap_complete::generate( + generator, + &mut Cli::command(), + env!("CARGO_BIN_NAME"), + &mut io::stdout(), + ); + + ExitCode::SUCCESS + } } }