Skip to content

Commit

Permalink
feat: add generate-completions cmd., support Nushell
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Aug 1, 2024
1 parent 8dcde14 commit 3f1f974
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions moz-webgpu-cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
23 changes: 22 additions & 1 deletion moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 3f1f974

Please sign in to comment.