mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
Merge pull request #4150 from epage/parent-usage
fix(usage): Don't include irrelevant parent args
This commit is contained in:
commit
4371a7b6cd
2 changed files with 49 additions and 10 deletions
|
@ -4336,7 +4336,8 @@ impl<'help> App<'help> {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
let mut mid_string = String::from(" ");
|
let mut mid_string = String::from(" ");
|
||||||
if !self.is_subcommand_negates_reqs_set() {
|
if !self.is_subcommand_negates_reqs_set() && !self.is_args_conflicts_with_subcommands_set()
|
||||||
|
{
|
||||||
let reqs = Usage::new(self).get_required_usage_from(&[], None, true); // maybe Some(m)
|
let reqs = Usage::new(self).get_required_usage_from(&[], None, true); // maybe Some(m)
|
||||||
|
|
||||||
for s in &reqs {
|
for s in &reqs {
|
||||||
|
@ -4419,7 +4420,9 @@ impl<'help> App<'help> {
|
||||||
|
|
||||||
if !self.is_set(AppSettings::BinNameBuilt) {
|
if !self.is_set(AppSettings::BinNameBuilt) {
|
||||||
let mut mid_string = String::from(" ");
|
let mut mid_string = String::from(" ");
|
||||||
if !self.is_subcommand_negates_reqs_set() {
|
if !self.is_subcommand_negates_reqs_set()
|
||||||
|
&& !self.is_args_conflicts_with_subcommands_set()
|
||||||
|
{
|
||||||
let reqs = Usage::new(self).get_required_usage_from(&[], None, true); // maybe Some(m)
|
let reqs = Usage::new(self).get_required_usage_from(&[], None, true); // maybe Some(m)
|
||||||
|
|
||||||
for s in &reqs {
|
for s in &reqs {
|
||||||
|
|
|
@ -829,14 +829,6 @@ fn multi_level_sc_help() {
|
||||||
utils::assert_output(cmd, "ctest help subcmd multi", MULTI_SC_HELP, false);
|
utils::assert_output(cmd, "ctest help subcmd multi", MULTI_SC_HELP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_wrap_help() {
|
|
||||||
let cmd = Command::new("ctest")
|
|
||||||
.term_width(0)
|
|
||||||
.override_help(MULTI_SC_HELP);
|
|
||||||
utils::assert_output(cmd, "ctest --help", &format!("{}\n", MULTI_SC_HELP), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_wrap_default_help() {
|
fn no_wrap_default_help() {
|
||||||
let cmd = Command::new("ctest").version("1.0").term_width(0);
|
let cmd = Command::new("ctest").version("1.0").term_width(0);
|
||||||
|
@ -2857,6 +2849,50 @@ OPTIONS:
|
||||||
utils::assert_eq(EXPECTED, String::from_utf8(buf).unwrap());
|
utils::assert_eq(EXPECTED, String::from_utf8(buf).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parent_cmd_req_ignored_when_negates_reqs() {
|
||||||
|
static MULTI_SC_HELP: &str = "ctest-subcmd
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
ctest subcmd
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Print help information
|
||||||
|
";
|
||||||
|
|
||||||
|
let cmd = Command::new("ctest")
|
||||||
|
.arg(arg!(<input>))
|
||||||
|
.subcommand_negates_reqs(true)
|
||||||
|
.subcommand(Command::new("subcmd"));
|
||||||
|
utils::assert_output(cmd, "ctest subcmd --help", MULTI_SC_HELP, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parent_cmd_req_ignored_when_conflicts() {
|
||||||
|
static MULTI_SC_HELP: &str = "ctest-subcmd
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
ctest subcmd
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h, --help Print help information
|
||||||
|
";
|
||||||
|
|
||||||
|
let cmd = Command::new("ctest")
|
||||||
|
.arg(arg!(<input>))
|
||||||
|
.args_conflicts_with_subcommands(true)
|
||||||
|
.subcommand(Command::new("subcmd"));
|
||||||
|
utils::assert_output(cmd, "ctest subcmd --help", MULTI_SC_HELP, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_wrap_help() {
|
||||||
|
let cmd = Command::new("ctest")
|
||||||
|
.term_width(0)
|
||||||
|
.override_help(MULTI_SC_HELP);
|
||||||
|
utils::assert_output(cmd, "ctest --help", &format!("{}\n", MULTI_SC_HELP), false);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_name_default() {
|
fn display_name_default() {
|
||||||
let mut cmd = Command::new("app").bin_name("app.exe");
|
let mut cmd = Command::new("app").bin_name("app.exe");
|
||||||
|
|
Loading…
Reference in a new issue