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() {
3333
3434 // Capture git describe output for the version command
3535 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 ])
3739 .current_dir(std::env::var("CARGO_MANIFEST_DIR").unwrap())
3840 .output()
3941 {
4042 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();
4245 println!("cargo::rustc-env=GIT_DESCRIBE={}", describe);
4346 println!("cargo::warning=weechat-matrix git describe: {}", describe);
4447 } else {
src/commands/access.rs +3 −19
@@ -36,15 +36,12 @@ impl RoomAccessCommand {
3636 pub fn create(servers: &Servers) -> Result<Command, ()> {
3737 let settings = CommandSettings::new("room")
3838 .description("Change access rules for the current Matrix room.")
39 .add_argument("make_public|make_invite_only")
4039 .add_argument("set_join_rule <public|invite|knock|private>")
4140 .arguments_description(
42 "make_public: Allow anyone to join the room.\n\
43 make_invite_only: Require an invitation to join.\n\
44 set_join_rule: Set the join rule to public, invite, knock, or private.",
41 "set_join_rule: Set the join rule to public, invite, knock, or private.",
4542 )
4643 .add_completion(
47 "make_public|make_invite_only|set_join_rule public|invite|knock|private",
44 "set_join_rule public|invite|knock|private",
4845 );
4946
5047 Command::new(
@@ -61,8 +58,6 @@ impl RoomAccessCommand {
6158 ArgParseSettings::DisableHelpFlags,
6259 ArgParseSettings::DisableVersion,
6360 ])
64 .subcommand(SubCommand::with_name("make_public"))
65 .subcommand(SubCommand::with_name("make_invite_only"))
6661 .subcommand(
6762 SubCommand::with_name("set_join_rule")
6863 .arg(Arg::with_name("rule").required(true)),
@@ -71,8 +66,6 @@ impl RoomAccessCommand {
7166
7267 fn action(matches: &clap::ArgMatches) -> Result<AccessAction, String> {
7368 match matches.subcommand() {
74 ("make_public", _) => Ok(AccessAction::Public),
75 ("make_invite_only", _) => Ok(AccessAction::Invite),
7669 ("set_join_rule", Some(args)) => match args.value_of("rule") {
7770 Some("public") => Ok(AccessAction::Public),
7871 Some("invite") | Some("invite_only") => Ok(AccessAction::Invite),
@@ -84,7 +77,7 @@ impl RoomAccessCommand {
8477 )),
8578 None => Err("A join rule is required.".to_owned()),
8679 },
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()),
8881 }
8982 }
9083
@@ -128,15 +121,6 @@ mod tests {
128121 RoomAccessCommand::action(&matches)
129122 }
130123
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
140124 #[test]
141125 fn generic_command_accepts_public_and_invite_rules() {
142126 assert_eq!(