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]]
887name = "clap_complete"
888version = "4.6.7"
889source = "registry+https://github.com/rust-lang/crates.io-index"
890checksum = "db8b397918185f0161ff3d6fcaa9e4bfc09b8367caf6e1d4a2848e5477ed027b"
891dependencies = [
892 "clap",
893]
894
886[[package]] 895[[package]]
887name = "clap_derive" 896name = "clap_derive"
888version = "4.6.1" 897version = "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"]
28anyhow = "1.0" 28anyhow = "1.0"
29bitflags = "2.3" 29bitflags = "2.3"
30chrono = "0.4" 30chrono = "0.4"
31clap = {version = "4.3", features = ["derive"]} 31clap = {version = "^4.6", features = ["derive"]}
32clap_complete = "^4.6"
32css-color-parser = "0.1.2" 33css-color-parser = "0.1.2"
33dirs = "6.0" 34dirs = "6.0"
34edit = "0.1.4" 35edit = "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)]
131pub struct Iamb { 131pub 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};
27use std::sync::Arc; 27use std::sync::Arc;
28use std::time::{Duration, Instant}; 28use std::time::{Duration, Instant};
29 29
30use clap::Parser; 30use clap::{CommandFactory, Parser};
31use matrix_sdk::ruma::api::error::ErrorKind; 31use matrix_sdk::ruma::api::error::ErrorKind;
32use matrix_sdk::ruma::OwnedUserId; 32use matrix_sdk::ruma::OwnedUserId;
33use matrix_sdk_crypto::encrypt_room_key_export; 33use 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