Commit 49d8542f31
49d8542f31265ee144d38de61bdd74f92e516860
parent: cbd361d947
Unregistered key
Jon Heinritz <jon.heinritz@protonmail.com> · 2026-07-24 19:30 UTC
committer: <noreply@github.com>
Support generating shell-completions using `clap_complete` (#489)
Layout: unified · split
Cargo.lock
+10
| @@ -883,6 +883,15 @@ dependencies = [ |
| 883 | 883 | "strsim", |
| 884 | 884 | ] |
| 885 | 885 | |
| 886 | [[package]] |
| 887 | name = "clap_complete" |
| 888 | version = "4.6.7" |
| 889 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 890 | checksum = "db8b397918185f0161ff3d6fcaa9e4bfc09b8367caf6e1d4a2848e5477ed027b" |
| 891 | dependencies = [ |
| 892 | "clap", |
| 893 | ] |
| 894 | |
| 886 | 895 | [[package]] |
| 887 | 896 | name = "clap_derive" |
| 888 | 897 | version = "4.6.1" |
| @@ -2349,6 +2358,7 @@ dependencies = [ |
| 2349 | 2358 | "bitflags 2.13.0", |
| 2350 | 2359 | "chrono", |
| 2351 | 2360 | "clap", |
| 2361 | "clap_complete", |
| 2352 | 2362 | "comrak", |
| 2353 | 2363 | "css-color-parser", |
| 2354 | 2364 | "dirs", |
Cargo.toml
+2 −1
| @@ -28,7 +28,8 @@ features = ["build"] |
| 28 | 28 | anyhow = "1.0" |
| 29 | 29 | bitflags = "2.3" |
| 30 | 30 | chrono = "0.4" |
| 31 | | clap = {version = "4.3", features = ["derive"]} |
| 31 | clap = {version = "^4.6", features = ["derive"]} |
| 32 | clap_complete = "^4.6" |
| 32 | 33 | css-color-parser = "0.1.2" |
| 33 | 34 | dirs = "6.0" |
| 34 | 35 | edit = "0.1.4" |
src/config.rs
+3
| @@ -129,6 +129,9 @@ const VERSION: &str = match option_env!("VERGEN_GIT_SHA") { |
| 129 | 129 | #[clap(version = VERSION, about, long_about = None)] |
| 130 | 130 | #[clap(propagate_version = true)] |
| 131 | 131 | pub struct Iamb { |
| 132 | #[clap(long, value_parser)] |
| 133 | pub completions: Option<clap_complete::Shell>, |
| 134 | |
| 132 | 135 | #[clap(short = 'P', long, value_parser)] |
| 133 | 136 | pub profile: Option<String>, |
| 134 | 137 | |
src/main.rs
+6 −1
| @@ -27,7 +27,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; |
| 27 | 27 | use std::sync::Arc; |
| 28 | 28 | use std::time::{Duration, Instant}; |
| 29 | 29 | |
| 30 | | use clap::Parser; |
| 30 | use clap::{CommandFactory, Parser}; |
| 31 | 31 | use matrix_sdk::ruma::api::error::ErrorKind; |
| 32 | 32 | use matrix_sdk::ruma::OwnedUserId; |
| 33 | 33 | use matrix_sdk_crypto::encrypt_room_key_export; |
| @@ -1133,6 +1133,11 @@ fn main() { |
| 1133 | 1133 | // Parse command-line flags. |
| 1134 | 1134 | let iamb = Iamb::parse(); |
| 1135 | 1135 | |
| 1136 | if let Some(shell) = iamb.completions { |
| 1137 | clap_complete::generate(shell, &mut Iamb::command(), "iamb", &mut std::io::stdout()); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
| 1136 | 1141 | // Load configuration and set up the Matrix SDK. |
| 1137 | 1142 | let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit); |
| 1138 | 1143 | |