-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve help message readability #261
base: main
Are you sure you want to change the base?
Improve help message readability #261
Conversation
@janhencic that's a bit of effort, but why comments rather than explicit command descriptions like before? You mentioned "few places" but, for me it's not clear what impact is, except, we lose explicit cli help definition. |
I switched to doc comments because passing long strings to macro attributes can make the code harder to read. Clap provides an alternative approach. It can parse doc comments, and use them to populate See Clap docs for more details. Code ExampleBelow is an example of the two approaches. The first embeds all help text in the Before#[derive(Debug, Args)]
pub struct DeployOpts {
#[arg(
value_name = "LIMIT",
default_value_t,
long,
help = "Evaluation node limit",
long_help = r#"Limits the maximum number of hosts to be evaluated at once.
The evaluation process is RAM-intensive. The default behavior is to limit the maximum number of host evaluated at the same time based on naive heuristics.
Set to 0 to disable the limit.
"#
)]
eval_node_limit: EvaluationNodeLimit, After#[derive(Debug, Args)]
pub struct DeployOpts {
/// Evaluation node limit
///
/// Limits the maximum number of hosts to be evaluated at once. The evaluation process is
/// RAM-intensive. The default behavior is to limit the maximum number of hosts evaluated at
/// the same time based on naive heuristics.
///
/// Set to 0 to disable the limit.
#[arg(value_name = "LIMIT", default_value_t, long)] What changes
Help is still explicitly defined—just in a different format. The way it works is that Clap splits doc comments into three distinct sections:
The short summary becomes the The catch is that the short summary is now reused within the long help, so you can’t separate them entirely as before. Instead, both pieces of text are concatenated, which means combine them carefully in a way that makes sense. As a result, you may see slight differences in the final result, as compared to before. Below is an example. I could provide more in a follow up response, if needed. Command-Line help examplesShort Help (Before & After)
Long Help (Before & After)
|
Related issue: #260
This PR refactors our Clap command and argument definitions by moving the inline
help
andlong_help
attributes into Rust doc comments. The same thing was done withabout
andlong_about
attributes. While this causes slightly different output in a few places, it results in more readable and maintainable code overall.Additionally, the
wrap_help
feature has been enabled to neatly format these doc comments in the CLI help text, andCargo.lock
now includes the terminal_size crate to support dynamic help wrapping.