feat: Use clap help instead of custom #5

Merged
aviac merged 2 commits from lorax/clap into main 2025-07-31 14:47:24 +00:00
Owner
  • the ! is now the caller instead of the command name
  • this enables things like !help <command> to show it's description
  • therefore the custom help text is no longer needed
  • this way the bot acts more like a familiar cli
  • also we get the bot version info for free ^^
* the ! is now the caller instead of the command name * this enables things like `!help <command>` to show it's description * therefore the custom help text is no longer needed * this way the bot acts more like a familiar cli * also we get the bot version info for free ^^
* the ! is now the caller instead of the command name
* this enables things like `!help <command>` to show it's description
* therefore the custom help text is no longer needed
* this way the bot acts more like a familiar cli
* also we get the bot version info for free ^^
lorax requested review from aviac 2025-07-31 09:57:14 +00:00
lorax changed target branch from lorax/creds to use-clap 2025-07-31 10:00:56 +00:00
aviac requested changes 2025-07-31 11:13:40 +00:00
Dismissed
aviac left a comment
Owner

Woah, richtig nice! Schoen simpel jetzt alles 💯 Noch ein paar Kleinigkeiten, aber ansonsten koennen wir das basically mergen

Woah, richtig nice! Schoen simpel jetzt alles 💯 Noch ein paar Kleinigkeiten, aber ansonsten koennen wir das basically mergen
@ -73,29 +74,18 @@ pub async fn execute_commands(
client: Client,
message: &str,
) -> anyhow::Result<()> {
let binary_name = std::env::args()
.next()
.context("Binary name not found! Aborting!")?;
let binary_name = "!";
Owner

Bitte kommentieren. Das hat mich gerade verwirrt. Ich dachte, dass Args::try_parse_from den richtigen binary namen vom rust crate benoetigt oder sonst abschmiert. Das Ding wird ja aber anscheinend

  1. nicht gecheckt
  2. verwendet um die help message zu bauen

Das war mir sehr neu und irgendwie nicht intuitiv

Bitte kommentieren. Das hat mich gerade verwirrt. Ich dachte, dass `Args::try_parse_from` den richtigen binary namen vom rust crate benoetigt oder sonst abschmiert. Das Ding wird ja aber anscheinend 1. nicht gecheckt 2. verwendet um die help message zu bauen Das war mir sehr neu und irgendwie nicht intuitiv
Author
Owner

^^'

^^'
@ -73,29 +74,18 @@ pub async fn execute_commands(
client: Client,
message: &str,
) -> anyhow::Result<()> {
let binary_name = std::env::args()
.next()
.context("Binary name not found! Aborting!")?;
let binary_name = "!";
let mut msg_args = message.split_whitespace();
let cmd = message.split_whitespace();
Owner

Wenn wir nicht nur das erste arg nehmen, welche implications hat das dann noch? Also zum Beispiel

!help me

waere dann invalid ... naja, geht vielleicht sogar wenn es die error message ordentlich printed. Hmm bin noch nicht so sicher.

Also ja, lass uns das so machen.

Wenn wir nicht nur das erste arg nehmen, welche implications hat das dann noch? Also zum Beispiel `!help me` waere dann invalid ... naja, geht vielleicht sogar wenn es die error message ordentlich printed. Hmm bin noch nicht so sicher. Also ja, lass uns das so machen.
Author
Owner

Ist eigentlich aussagekräftig

error: unrecognized subcommand 'me'

Usage: ! <COMMAND>

For more information, try '--help'.
Ist eigentlich aussagekräftig ``` error: unrecognized subcommand 'me' Usage: ! <COMMAND> For more information, try '--help'. ```
@ -38,7 +37,9 @@ async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room, client
return;
}
if let Err(error) = execute_commands(room, event, client, message).await {
if let Err(error) =
execute_commands(room, event, client, message.strip_prefix("!").unwrap()).await
Owner

Mit dem unwrap() stuerzt der bot jedes mal ab wenn keine command nachricht kommt. Also wie checken das schon vorher, aber es ist vielleicht besser hier wenigstens nen Kommentar dranzuschreiben, wenn nicht sogar das bisschen zu refactoren, sodass es den case wo es None ist ordentlich handlet

Mit dem `unwrap()` stuerzt der bot jedes mal ab wenn keine command nachricht kommt. Also wie checken das schon vorher, aber es ist vielleicht besser hier wenigstens nen Kommentar dranzuschreiben, wenn nicht sogar das bisschen zu refactoren, sodass es den case wo es `None` ist ordentlich handlet
Author
Owner

Also das wäre sicherlich schöner, aber oben wird ja schon returned, wenn die Nachricht nicht den prefix '!' hat. Demnach sollte der Bot nicht abstürzen.

Also das wäre sicherlich schöner, aber oben wird ja schon returned, wenn die Nachricht nicht den prefix '!' hat. Demnach sollte der Bot nicht abstürzen.
Owner

In solchen Faellen ist ein unwrap einfach meist ein Zeichen dafuer, dass irgendwas noch nicht ganz stimmig ist. Mit der Zeit werden unwraps immer mehr ein Dorn im Auge einfach auch wenn sie am Anfang komfortabel sind ^^

Ich hab's mal in a47e5570bc 'gefixt'

In solchen Faellen ist ein `unwrap` einfach meist ein Zeichen dafuer, dass irgendwas noch nicht ganz stimmig ist. Mit der Zeit werden `unwrap`s immer mehr ein Dorn im Auge einfach auch wenn sie am Anfang komfortabel sind ^^ Ich hab's mal in a47e5570bcb0d36a35a2e139fe8c8962ced68267 'gefixt'
aviac changed target branch from use-clap to main 2025-07-31 11:29:18 +00:00
aviac left a comment
Owner

Und bitte nochmal rebasen. Der PR hier hat jetzt 3 merge commits, die dann hoffentlich weg sind.

Und bitte nochmal rebasen. Der PR hier hat jetzt 3 merge commits, die dann hoffentlich weg sind.
lorax requested review from aviac 2025-07-31 13:09:49 +00:00
aviac merged commit 71d3f9eff3 into main 2025-07-31 14:47:24 +00:00
aviac deleted branch lorax/clap 2025-07-31 14:47:24 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
solarpunk-kollektiv-dd/soko-command-bot!5
No description provided.