Skip to content

Commit

Permalink
Add AlignAll setting
Browse files Browse the repository at this point in the history
That's in preparation of clap-rs#1013: provide option to layout the output
of "my_program --help" with the same alignment across sections.
  • Loading branch information
pierrechevalier83 committed Jan 6, 2019
1 parent 3294d18 commit 1041a75
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bitflags! {
const INFER_SUBCOMMANDS = 1 << 38;
const CONTAINS_LAST = 1 << 39;
const ARGS_OVERRIDE_SELF = 1 << 40;
const ALIGN_ALL = 1 << 41;
}
}

Expand Down Expand Up @@ -109,6 +110,7 @@ impl AppFlags {
NextLineHelp => Flags::NEXT_LINE_HELP,
VersionlessSubcommands => Flags::VERSIONLESS_SC,
WaitOnError => Flags::WAIT_ON_ERROR,
AlignAll => Flags::ALIGN_ALL,
TrailingValues => Flags::TRAILING_VALUES,
ValidNegNumFound => Flags::VALID_NEG_NUM_FOUND,
Propagated => Flags::PROPAGATED,
Expand Down Expand Up @@ -926,6 +928,42 @@ pub enum AppSettings {
/// ```
/// [`SubCommand`]: ./struct.SubCommand.html
WaitOnError,
/// Will display the help comments aligned across different sections
///
/// This is most useful for applications that have a small number of subsections where the
/// default help visualisation may look messy.
///
/// # Example:
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .setting(AppSettings::AlignAll);
/// # ;
/// ```
///
/// Instead of looking like so:
/// FLAGS:
/// -h, --help Prints help information
/// -V, --version Prints version information
///
/// OPTIONS:
/// -l <library>... Adds a library to be injected
///
/// ARGS:
/// <command>... The command to be executed
///
/// the output would look like so:
/// FLAGS:
/// -h, --help Prints help information
/// -V, --version Prints version information
///
/// OPTIONS:
/// -l <library>... Adds a library to be injected
///
/// ARGS:
/// <command>... The command to be executed
AlignAll,

#[doc(hidden)] NeedsLongVersion,

Expand Down Expand Up @@ -980,6 +1018,7 @@ impl FromStr for AppSettings {
"unifiedhelpmessage" => Ok(AppSettings::UnifiedHelpMessage),
"versionlesssubcommands" => Ok(AppSettings::VersionlessSubcommands),
"waitonerror" => Ok(AppSettings::WaitOnError),
"alignall" => Ok(AppSettings::AlignAll),
"validnegnumfound" => Ok(AppSettings::ValidNegNumFound),
"validargfound" => Ok(AppSettings::ValidArgFound),
"propagated" => Ok(AppSettings::Propagated),
Expand Down Expand Up @@ -1111,6 +1150,10 @@ mod test {
"waitonerror".parse::<AppSettings>().unwrap(),
AppSettings::WaitOnError
);
assert_eq!(
"alignall".parse::<AppSettings>().unwrap(),
AppSettings::AlignAll
);
assert_eq!(
"validnegnumfound".parse::<AppSettings>().unwrap(),
AppSettings::ValidNegNumFound
Expand Down

0 comments on commit 1041a75

Please sign in to comment.