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

docs: How to override multi-line usage #4112

Merged
merged 1 commit into from Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/builder/command.rs
Expand Up @@ -1648,6 +1648,14 @@ impl<'help> App<'help> {
/// strings. After this setting is set, this will be *the only* usage string
/// displayed to the user!
///
/// **NOTE:** Multiple usage lines may be present in the usage argument, but
/// some rules need to be followed to ensure the usage lines are formatted
/// correctly by the default help formatter:
///
/// - Do not indent the first usage line.
/// - Indent all subsequent usage lines with four spaces.
/// - The last line must not end with a newline.
///
/// # Examples
///
/// ```no_run
Expand All @@ -1656,6 +1664,20 @@ impl<'help> App<'help> {
/// .override_usage("myapp [-clDas] <some_file>")
/// # ;
/// ```
///
/// Or for multiple usage lines:
///
/// ```no_run
/// # use clap::{Command, Arg};
/// Command::new("myprog")
/// .override_usage(
/// "myapp -X [-a] [-b] <file>\n \
/// myapp -Y [-c] <file1> <file2>\n \
/// myapp -Z [-d|-e]"
/// )
/// # ;
/// ```
///
/// [`ArgMatches::usage`]: ArgMatches::usage()
#[must_use]
pub fn override_usage<S: Into<&'help str>>(mut self, usage: S) -> Self {
Expand Down