Skip to content

Commit d429763

Browse files
authored
Merge pull request #2115 from jdonszelmann/case-insensitive-zulip
make matching case-insensitive on zulip
2 parents 5c4f2b1 + 20f335f commit d429763

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ignore = "0.4.18"
4444
postgres-types = { version = "0.2.4", features = ["derive"] }
4545
cron = { version = "0.15.0" }
4646
bytes = "1.1.0"
47-
clap = { version = "4", features = ["derive"] }
47+
clap = { version = "4", features = ["derive", "string"] }
4848
hmac = "0.12.1"
4949
subtle = "2.6.1"
5050
sha2 = "0.10.9"

src/zulip/commands.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,25 @@ pub struct PingGoalsArgs {
175175

176176
/// Helper function to parse CLI arguments without any colored help or error output.
177177
pub fn parse_cli<'a, T: Parser, I: Iterator<Item = &'a str>>(input: I) -> anyhow::Result<T> {
178+
fn allow_title_case(sub: clap::Command) -> clap::Command {
179+
let name = sub.get_name();
180+
let alias = name
181+
.chars()
182+
.enumerate()
183+
.map(|(i, c)| if i == 0 { c.to_ascii_uppercase() } else { c })
184+
.collect::<String>();
185+
sub.alias(alias)
186+
// Recursively allow title-case subcommands
187+
.mut_subcommands(allow_title_case)
188+
}
189+
178190
// Add a fake first argument, which is expected by clap
179191
let input = std::iter::once("triagebot").chain(input);
180192

181193
let matches = T::command()
182194
.color(ColorChoice::Never)
195+
// Allow title-case subcommands
196+
.mut_subcommands(allow_title_case)
183197
.try_get_matches_from(input)?;
184198
let value = T::from_arg_matches(&matches)?;
185199
Ok(value)
@@ -234,6 +248,11 @@ mod tests {
234248
assert_eq!(parse_chat(&["whoami"]), ChatCommand::Whoami);
235249
}
236250

251+
#[test]
252+
fn whoami_uppercased_command() {
253+
assert_eq!(parse_chat(&["Whoami"]), ChatCommand::Whoami);
254+
}
255+
237256
#[test]
238257
fn lookup_command() {
239258
assert_eq!(
@@ -259,6 +278,14 @@ mod tests {
259278
);
260279
}
261280

281+
#[test]
282+
fn work_uppercased_command() {
283+
assert_eq!(
284+
parse_chat(&["Work", "Show"]),
285+
ChatCommand::Work(WorkqueueCmd::Show)
286+
);
287+
}
288+
262289
#[test]
263290
fn end_meeting_command() {
264291
assert_eq!(parse_stream(&["end-meeting"]), StreamCommand::EndMeeting);

0 commit comments

Comments
 (0)