Help message in String from Parser #3498
Tony-Goat
started this conversation in
Show and tell
Replies: 2 comments
-
Great use case! btw
I'd recommend using |
Beta Was this translation helpful? Give feedback.
0 replies
-
btw the derive reference now explicitly mentions |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recently I've had trouble generating a help message into a string from a parser, however, I found the solution and thought I should share it for anyone else having trouble.
To do this safely, you need to have
clap::Command
,clap::CommandFactory
,clap::ErrorKind
andclap::Parser
, andstd::io::BufWriter
in your uses. I wrote this code assuming that your function signature looks similar tofn function_name(args: String) -> String
This is mostly useful for bots that accept commands from an interface other than CLI (e.g. a Discord bot). Your help parsing my look something akin to this:
If you want to see how I use it specifically, you can see my repository for the Multi-Target Bot Specialist in src/bot_worker/openlegend.rs line 186. I also use Clap to parse the arguments in the bookmark command, however, I am working on porting that from 2.34.
Beta Was this translation helpful? Give feedback.
All reactions