Skip to content

Commit 401fb04

Browse files
committed
feat(cli): add shell completions command
1 parent 4ba0df5 commit 401fb04

5 files changed

Lines changed: 29 additions & 1 deletion

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rust-version = "1.88"
2525
[workspace.dependencies]
2626
blake3 = { version = "1.8.2", features = ["mmap"] }
2727
clap = { version = "4.5.54", features = ["cargo", "derive"] }
28+
clap_complete = "4.6.3"
2829
chrono = "0.4"
2930
compak = "0.1.2"
3031
diesel = { version = "2.3.5", features = [

crates/soar-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ self = []
1919

2020
[dependencies]
2121
clap = { workspace = true }
22+
clap_complete = { workspace = true }
2223
indicatif = { workspace = true }
2324
miette = { workspace = true }
2425
nix = { workspace = true }

crates/soar-cli/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{ArgAction, Parser, Subcommand, ValueHint};
2+
use clap_complete::Shell;
23

34
use crate::utils::parse_default_repos_arg;
45

@@ -527,6 +528,14 @@ pub enum Commands {
527528
#[clap(name = "defpackages")]
528529
DefPackages,
529530

531+
/// Generate shell completions
532+
#[clap(name = "completions")]
533+
Completions {
534+
/// Shell to generate completions for
535+
#[arg(value_enum)]
536+
shell: Shell,
537+
},
538+
530539
/// Convert JSON metadata to SQLite database
531540
#[clap(name = "json2db")]
532541
Json2Db {

crates/soar-cli/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::{
66
};
77

88
use apply::apply_packages;
9-
use clap::Parser;
9+
use clap::{CommandFactory, Parser};
10+
use clap_complete;
1011
use cli::Args;
1112
use download::{create_regex_patterns, download, DownloadContext};
1213
use health::{display_health, remove_broken_packages};
@@ -475,6 +476,12 @@ async fn handle_cli() -> SoarResult<()> {
475476
} => {
476477
json_to_db(&input, &output, repo.as_deref())?;
477478
}
479+
cli::Commands::Completions {
480+
shell,
481+
} => {
482+
let mut cmd = cli::Args::command();
483+
clap_complete::generate(shell, &mut cmd, "soar", &mut std::io::stdout());
484+
}
478485
_ => unreachable!(),
479486
}
480487

0 commit comments

Comments
 (0)