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

fix(help): Subcommand help looks like --help #3451

Merged
merged 1 commit into from Feb 11, 2022
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion examples/tutorial_builder/03_04_subcommands.rs
Expand Up @@ -3,7 +3,6 @@ use clap::{app_from_crate, arg, App, AppSettings};
fn main() {
let matches = app_from_crate!()
.propagate_version(true)
.global_setting(AppSettings::UseLongFormatForHelpSubcommand)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
App::new("add")
Expand Down
3 changes: 1 addition & 2 deletions examples/tutorial_derive/03_04_subcommands.rs
@@ -1,9 +1,8 @@
use clap::{AppSettings, Parser, Subcommand};
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
#[clap(global_setting(AppSettings::UseLongFormatForHelpSubcommand))]
struct Cli {
#[clap(subcommand)]
command: Commands,
Expand Down
22 changes: 2 additions & 20 deletions src/build/app_settings.rs
Expand Up @@ -176,26 +176,8 @@ pub enum AppSettings {
)]
AllowInvalidUtf8ForExternalSubcommands,

/// Specifies that the help subcommand should print the long help message (`--help`).
///
/// **NOTE:** This setting is useless if [`AppSettings::DisableHelpSubcommand`] or [`AppSettings::NoAutoHelp`] is set,
/// or if the app contains no subcommands at all.
///
/// # Examples
///
/// ```rust
/// # use clap::{App, Arg, AppSettings};
/// App::new("myprog")
/// .global_setting(AppSettings::UseLongFormatForHelpSubcommand)
/// .subcommand(App::new("test")
/// .arg(Arg::new("foo")
/// .help("short form about message")
/// .long_help("long form about message")
/// )
/// )
/// .get_matches();
/// ```
/// [long format]: crate::App::long_about
/// Deprecated, this is now the default
#[deprecated(since = "3.1.0", note = "This is now the default")]
UseLongFormatForHelpSubcommand,

/// Deprecated, replaced with [`App::subcommand_negates_reqs`] and
Expand Down
2 changes: 1 addition & 1 deletion src/parse/parser.rs
Expand Up @@ -661,7 +661,7 @@ impl<'help, 'app> Parser<'help, 'app> {

let parser = Parser::new(&mut sc);

Err(parser.help_err(self.app.is_set(AS::UseLongFormatForHelpSubcommand)))
Err(parser.help_err(true))
}

fn is_new_arg(&self, next: &RawOsStr, current_positional: &Arg) -> bool {
Expand Down
105 changes: 0 additions & 105 deletions tests/builder/app_settings.rs
Expand Up @@ -79,54 +79,6 @@ SUBCOMMANDS:
info
";

static LONG_FORMAT_FOR_HELP_SUBCOMMAND: &str = "myprog-test

USAGE:
myprog test [foo]

ARGS:
<foo>
long form help message

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

static LONG_FORMAT_FOR_NESTED_HELP_SUBCOMMAND: &str = "myprog-test-nested
long form about message

USAGE:
myprog test nested

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

static LONG_FORMAT_SINGLE_ARG_HELP_SUBCOMMAND: &str = "myprog 1.0

USAGE:
myprog [foo] [SUBCOMMAND]

ARGS:
<foo>
long form help message

OPTIONS:
-h, --help
Print help information

-V, --version
Print version information

SUBCOMMANDS:
help
Print this message or the help of the given subcommand(s)
test

";

#[test]
fn setting() {
#![allow(deprecated)]
Expand Down Expand Up @@ -1137,63 +1089,6 @@ fn aaos_option_use_delim_false() {
);
}

#[test]
fn nested_help_subcommand_with_global_setting() {
let m = App::new("myprog")
.global_setting(AppSettings::UseLongFormatForHelpSubcommand)
.subcommand(
App::new("test").subcommand(
App::new("nested")
.about("short form about message")
.long_about("long form about message"),
),
);
assert!(utils::compare_output(
m,
"myprog test help nested",
LONG_FORMAT_FOR_NESTED_HELP_SUBCOMMAND,
false
));
}

#[test]
fn single_arg_help_with_long_format_setting() {
let m = App::new("myprog")
.version("1.0")
.setting(AppSettings::UseLongFormatForHelpSubcommand)
.subcommand(App::new("test"))
.arg(
Arg::new("foo")
.help("short form help message")
.long_help("long form help message"),
);
assert!(utils::compare_output(
m,
"myprog help",
LONG_FORMAT_SINGLE_ARG_HELP_SUBCOMMAND,
false
));
}

#[test]
fn use_long_format_for_help_subcommand_with_setting() {
let m = App::new("myprog")
.setting(AppSettings::UseLongFormatForHelpSubcommand)
.subcommand(
App::new("test").arg(
Arg::new("foo")
.help("short form help message")
.long_help("long form help message"),
),
);
assert!(utils::compare_output(
m,
"myprog help test",
LONG_FORMAT_FOR_HELP_SUBCOMMAND,
false
));
}

#[test]
fn no_auto_help() {
let app = App::new("myprog")
Expand Down
1 change: 0 additions & 1 deletion tests/derive/structopt.rs
Expand Up @@ -7,7 +7,6 @@ fn compatible() {
#[derive(StructOpt)]
#[structopt(author, version, about)]
#[structopt(global_setting(AppSettings::PropagateVersion))]
#[structopt(global_setting(AppSettings::UseLongFormatForHelpSubcommand))]
struct Cli {
#[structopt(subcommand)]
command: Commands,
Expand Down