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 | "strsim", |
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 | [[package]] |
895 | [[package]] |
| 887 | name = "clap_derive" |
896 | name = "clap_derive" |
| 888 | version = "4.6.1" |
897 | version = "4.6.1" |
| @@ -2349,6 +2358,7 @@ dependencies = [ |
| 2349 | "bitflags 2.13.0", |
2358 | "bitflags 2.13.0", |
| 2350 | "chrono", |
2359 | "chrono", |
| 2351 | "clap", |
2360 | "clap", |
| |
2361 | "clap_complete", |
| 2352 | "comrak", |
2362 | "comrak", |
| 2353 | "css-color-parser", |
2363 | "css-color-parser", |
| 2354 | "dirs", |
2364 | "dirs", |
Cargo.toml
+2 −1
| @@ -28,7 +28,8 @@ features = ["build"] |
| 28 | anyhow = "1.0" |
28 | anyhow = "1.0" |
| 29 | bitflags = "2.3" |
29 | bitflags = "2.3" |
| 30 | chrono = "0.4" |
30 | chrono = "0.4" |
| 31 | clap = {version = "4.3", features = ["derive"]} |
31 | clap = {version = "^4.6", features = ["derive"]} |
| |
32 | clap_complete = "^4.6" |
| 32 | css-color-parser = "0.1.2" |
33 | css-color-parser = "0.1.2" |
| 33 | dirs = "6.0" |
34 | dirs = "6.0" |
| 34 | edit = "0.1.4" |
35 | edit = "0.1.4" |
src/config.rs
+3
| @@ -129,6 +129,9 @@ const VERSION: &str = match option_env!("VERGEN_GIT_SHA") { |
| 129 | #[clap(version = VERSION, about, long_about = None)] |
129 | #[clap(version = VERSION, about, long_about = None)] |
| 130 | #[clap(propagate_version = true)] |
130 | #[clap(propagate_version = true)] |
| 131 | pub struct Iamb { |
131 | pub struct Iamb { |
| |
132 | #[clap(long, value_parser)] |
| |
133 | pub completions: Option<clap_complete::Shell>, |
| |
134 | |
| 132 | #[clap(short = 'P', long, value_parser)] |
135 | #[clap(short = 'P', long, value_parser)] |
| 133 | pub profile: Option<String>, |
136 | pub profile: Option<String>, |
| 134 | |
137 | |
src/main.rs
+6 −1
| @@ -27,7 +27,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; |
| 27 | use std::sync::Arc; |
27 | use std::sync::Arc; |
| 28 | use std::time::{Duration, Instant}; |
28 | use std::time::{Duration, Instant}; |
| 29 | |
29 | |
| 30 | use clap::Parser; |
30 | use clap::{CommandFactory, Parser}; |
| 31 | use matrix_sdk::ruma::api::error::ErrorKind; |
31 | use matrix_sdk::ruma::api::error::ErrorKind; |
| 32 | use matrix_sdk::ruma::OwnedUserId; |
32 | use matrix_sdk::ruma::OwnedUserId; |
| 33 | use matrix_sdk_crypto::encrypt_room_key_export; |
33 | use matrix_sdk_crypto::encrypt_room_key_export; |
| @@ -1133,6 +1133,11 @@ fn main() { |
| 1133 | // Parse command-line flags. |
1133 | // Parse command-line flags. |
| 1134 | let iamb = Iamb::parse(); |
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 | // Load configuration and set up the Matrix SDK. |
1141 | // Load configuration and set up the Matrix SDK. |
| 1137 | let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit); |
1142 | let settings = ApplicationSettings::load(iamb).unwrap_or_else(print_exit); |
| 1138 | |
1143 | |