Commit 87ebd7a6e4

87ebd7a6e4cf61ddd51b4a7e1f0665554e1dde09

parent: cefc84e099

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-08-08 22:48 UTC
committer: <strk@kbt.io>

Refine room access join-rule command

Layout: unified · split

build.rs +5 −2
@@ -33,12 +33,15 @@ fn main() {
33 33
34 // Capture git describe output for the version command 34 // Capture git describe output for the version command
35 if let Ok(output) = std::process::Command::new("git") 35 if let Ok(output) = std::process::Command::new("git")
36 .args(["describe", "--long", "--tags", "--always", "--all", "--dirty"]) 36 .args([
37 "describe", "--long", "--tags", "--always", "--all", "--dirty",
38 ])
37 .current_dir(std::env::var("CARGO_MANIFEST_DIR").unwrap()) 39 .current_dir(std::env::var("CARGO_MANIFEST_DIR").unwrap())
38 .output() 40 .output()
39 { 41 {
40 if output.status.success() { 42 if output.status.success() {
41 let describe = String::from_utf8_lossy(&output.stdout).trim().to_string(); 43 let describe =
44 String::from_utf8_lossy(&output.stdout).trim().to_string();
42 println!("cargo::rustc-env=GIT_DESCRIBE={}", describe); 45 println!("cargo::rustc-env=GIT_DESCRIBE={}", describe);
43 println!("cargo::warning=weechat-matrix git describe: {}", describe); 46 println!("cargo::warning=weechat-matrix git describe: {}", describe);
44 } else { 47 } else {
src/commands/access.rs +3 −19
@@ -36,15 +36,12 @@ impl RoomAccessCommand {
36 pub fn create(servers: &Servers) -> Result<Command, ()> { 36 pub fn create(servers: &Servers) -> Result<Command, ()> {
37 let settings = CommandSettings::new("room") 37 let settings = CommandSettings::new("room")
38 .description("Change access rules for the current Matrix room.") 38 .description("Change access rules for the current Matrix room.")
39 .add_argument("make_public|make_invite_only")
40 .add_argument("set_join_rule <public|invite|knock|private>") 39 .add_argument("set_join_rule <public|invite|knock|private>")
41 .arguments_description( 40 .arguments_description(
42 "make_public: Allow anyone to join the room.\n\ 41 "set_join_rule: Set the join rule to public, invite, knock, or private.",
43 make_invite_only: Require an invitation to join.\n\
44 set_join_rule: Set the join rule to public, invite, knock, or private.",
45 ) 42 )
46 .add_completion( 43 .add_completion(
47 "make_public|make_invite_only|set_join_rule public|invite|knock|private", 44 "set_join_rule public|invite|knock|private",
48 ); 45 );
49 46
50 Command::new( 47 Command::new(
@@ -61,8 +58,6 @@ impl RoomAccessCommand {
61 ArgParseSettings::DisableHelpFlags, 58 ArgParseSettings::DisableHelpFlags,
62 ArgParseSettings::DisableVersion, 59 ArgParseSettings::DisableVersion,
63 ]) 60 ])
64 .subcommand(SubCommand::with_name("make_public"))
65 .subcommand(SubCommand::with_name("make_invite_only"))
66 .subcommand( 61 .subcommand(
67 SubCommand::with_name("set_join_rule") 62 SubCommand::with_name("set_join_rule")
68 .arg(Arg::with_name("rule").required(true)), 63 .arg(Arg::with_name("rule").required(true)),
@@ -71,8 +66,6 @@ impl RoomAccessCommand {
71 66
72 fn action(matches: &clap::ArgMatches) -> Result<AccessAction, String> { 67 fn action(matches: &clap::ArgMatches) -> Result<AccessAction, String> {
73 match matches.subcommand() { 68 match matches.subcommand() {
74 ("make_public", _) => Ok(AccessAction::Public),
75 ("make_invite_only", _) => Ok(AccessAction::Invite),
76 ("set_join_rule", Some(args)) => match args.value_of("rule") { 69 ("set_join_rule", Some(args)) => match args.value_of("rule") {
77 Some("public") => Ok(AccessAction::Public), 70 Some("public") => Ok(AccessAction::Public),
78 Some("invite") | Some("invite_only") => Ok(AccessAction::Invite), 71 Some("invite") | Some("invite_only") => Ok(AccessAction::Invite),
@@ -84,7 +77,7 @@ impl RoomAccessCommand {
84 )), 77 )),
85 None => Err("A join rule is required.".to_owned()), 78 None => Err("A join rule is required.".to_owned()),
86 }, 79 },
87 _ => Err("Usage: /room make_public|make_invite_only|set_join_rule <public|invite|knock|private>".to_owned()), 80 _ => Err("Usage: /room set_join_rule <public|invite|knock|private>".to_owned()),
88 } 81 }
89 } 82 }
90 83
@@ -128,15 +121,6 @@ mod tests {
128 RoomAccessCommand::action(&matches) 121 RoomAccessCommand::action(&matches)
129 } 122 }
130 123
131 #[test]
132 fn explicit_shortcuts_select_join_rules() {
133 assert_eq!(Ok(AccessAction::Public), parse(&["room", "make_public"]));
134 assert_eq!(
135 Ok(AccessAction::Invite),
136 parse(&["room", "make_invite_only"])
137 );
138 }
139
140 #[test] 124 #[test]
141 fn generic_command_accepts_public_and_invite_rules() { 125 fn generic_command_accepts_public_and_invite_rules() {
142 assert_eq!( 126 assert_eq!(