Skip to content

Commit 7b4b05f

Browse files
feat: add generate-completions cmd., support Nushell
1 parent b6f5867 commit 7b4b05f

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

Cargo.lock

Lines changed: 27 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

moz-webgpu-cts/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ wax = { version = "0.6.0", features = [
4343
whippit = { version = "0.6.3", path = "../whippit", default-features = false, features = [
4444
"serde1",
4545
] }
46+
clap_complete = "4.5.5"
47+
clap_complete_nushell = "4.5.2"
4648

4749
[dev-dependencies]
4850
insta = { workspace = true }

moz-webgpu-cts/src/main.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::{
3333

3434
use crate::wpt::path::Browser;
3535
use camino::Utf8PathBuf;
36-
use clap::{Parser, ValueEnum};
36+
use clap::{CommandFactory, Parser, ValueEnum};
3737
use enumset::{EnumSet, EnumSetType};
3838
use indexmap::{IndexMap, IndexSet};
3939
use itertools::Itertools;
@@ -145,6 +145,8 @@ enum Subcommand {
145145
/// Dump all metadata as JSON. Do so at your own risk; no guarantees are made about the
146146
/// schema of this JSON, for now.
147147
DumpJson,
148+
/// Generate completions for various supported shells.
149+
GenerateCompletions { shell: CompletionShell },
148150
}
149151

150152
#[derive(Clone, Debug, clap::Args)]
@@ -257,6 +259,11 @@ enum UpdateBacklogCriteria {
257259
},
258260
}
259261

262+
#[derive(Clone, Copy, Debug, ValueEnum)]
263+
enum CompletionShell {
264+
Nushell,
265+
}
266+
260267
fn main() -> ExitCode {
261268
env_logger::builder()
262269
.filter_level(log::LevelFilter::Info)
@@ -1110,6 +1117,20 @@ fn run(cli: Cli) -> ExitCode {
11101117
}
11111118
}
11121119
}
1120+
Subcommand::GenerateCompletions { shell } => {
1121+
let generator = match shell {
1122+
CompletionShell::Nushell => clap_complete_nushell::Nushell,
1123+
};
1124+
1125+
clap_complete::generate(
1126+
generator,
1127+
&mut Cli::command(),
1128+
env!("CARGO_BIN_NAME"),
1129+
&mut io::stdout(),
1130+
);
1131+
1132+
ExitCode::SUCCESS
1133+
}
11131134
}
11141135
}
11151136

0 commit comments

Comments
 (0)