Skip to content
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

feat: Return help message as String for Command #3874

Closed
wants to merge 11 commits into from

Conversation

ychiguer
Copy link

@ychiguer ychiguer commented Jun 27, 2022

Fixes #3873

@ychiguer ychiguer force-pushed the master branch 2 times, most recently from a3087d3 to 50e5ea7 Compare June 27, 2022 12:59
src/builder/command.rs Outdated Show resolved Hide resolved
@@ -1117,6 +1121,7 @@ const TAB_WIDTH: usize = 4;
pub(crate) enum HelpWriter<'writer> {
Normal(&'writer mut dyn Write),
Buffer(&'writer mut Colorizer),
String(&'writer mut String),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a new HelpWriter needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to simplify writing to a String, but from the points you have made it shouldn't be necessary.

Comment on lines +751 to +753
Err(e) => {
panic!("{}", e.to_string())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either be returning an error or making it clear why a panic is unexpected to happen. The latter is the case for this. We have a common panic message for these cases (its INTERNAL something I think). We can just write_help().expect(INTERNAL_...)

@@ -708,6 +708,52 @@ impl<'help> App<'help> {
c.print()
}

/// Returns the help message (`-h`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these functions to a consistent location (we currently have short/long help grouped and show print followed by write variants).

Comment on lines +609 to +634
static SETUP_HELP_MESSAGE: &str = "test 1.3
Kevin K.
tests stuff

USAGE:
test

OPTIONS:
-h, --help Print help information
-V, --version Print version information
";

static SETUP_LONG_HELP_MESSAGE: &str = "test 1.3
Kevin K.
tests stuff

USAGE:
test

OPTIONS:
-h, --help
Print help information

-V, --version
Print version information
";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit; could you move these into the test function bodies?

A lot of older tests do this and the separation between the expected output and the rest of the test function makes it harder to follow. We've been writing new tests with the expected string in the body and updating the old tests piecemeal.

epage added a commit to epage/clap that referenced this pull request Sep 22, 2022
The writer is less convenient and isn't offering any performance
benefits of avoidign the extra allocations, so let's render instead.

This supersedes clap-rs#3874

Fixes clap-rs#3873
epage added a commit to epage/clap that referenced this pull request Sep 22, 2022
The writer is less convenient and isn't offering any performance
benefits of avoidign the extra allocations, so let's render instead.

This supersedes clap-rs#3874

Fixes clap-rs#3873
@epage
Copy link
Member

epage commented Sep 22, 2022

#4248 supersedes this

@epage epage closed this Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return help message as String for Command
2 participants