Skip to content

Commit

Permalink
docs: How to override multi-line usage
Browse files Browse the repository at this point in the history
Backport #4106 to v3-master branch.
  • Loading branch information
jpgrayson committed Aug 25, 2022
1 parent df30c1a commit 9620e12
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit 9620e12

Please sign in to comment.