Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Only print help for subsubcommand when global settings subcommandneededelsehelp #189

Open
2 tasks done
epage opened this issue Dec 6, 2021 · 0 comments
Open
2 tasks done

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by ZenithalHourlyRate
Tuesday Jun 01, 2021 at 08:03 GMT
Originally opened as clap-rs/clap#2513


Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Rust Version

rustc 1.52.1 (9bc8c42bb 2021-05-09)

Clap Version

2.33.3

Minimal reproducible code

main.rs

#[macro_use]
extern crate clap;
use clap::{App, ArgMatches};

fn genkey(matches: &ArgMatches) {
    match matches.subcommand() {
        ("b", _) => {
            println!("Reached here");
        },
        _ => unimplemented!(),
    }
}

fn main() {
    let yaml = load_yaml!("cli.yml");
    let matches = App::from(yaml)
        .get_matches();

    match matches.subcommand() {
        ("a", Some(matches)) => genkey(matches),
        _ => unreachable!(),
    }
}

cli.yml

name: foo
global_settings:
    - subcommandrequiredelsehelp
subcommands:
  - a:
      about: First layer subcommand
      subcommands:
        - b:
              about: Second layer subcommand

Steps to reproduce the bug with the above code

$ cargo r -- a b

Actual Behaviour

$ cargo r -- a b
   Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `/home/zenithal/T/test/target/debug/foo a b`
foo-a-b
Second layer subcommand

USAGE:
    foo a b

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

Expected Behaviour

$ cargo r -- a b
   Compiling foo v0.1.0 (/home/zenithal/T/test)
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `/home/zenithal/T/test/target/debug/foo a b`
Reached here

Additional Context

No response

Debug Output

DEBUG:clap:Parser::add_subcommand: term_w=None, name=b
DEBUG:clap:Parser::add_subcommand: term_w=None, name=a
DEBUG:clap:Parser::propagate_settings: self=foo, g_settings=AppFlags(
    SC_REQUIRED_ELSE_HELP,
)
DEBUG:clap:Parser::propagate_settings: sc=a, settings=AppFlags(
    NEEDS_LONG_HELP | NEEDS_LONG_VERSION | NEEDS_SC_HELP | UTF8_NONE | COLOR_AUTO,
), g_settings=AppFlags(
    (empty),
)
DEBUG:clap:Parser::propagate_settings: self=a, g_settings=AppFlags(
    SC_REQUIRED_ELSE_HELP,
)
DEBUG:clap:Parser::propagate_settings: sc=b, settings=AppFlags(
    NEEDS_LONG_HELP | NEEDS_LONG_VERSION | NEEDS_SC_HELP | UTF8_NONE | COLOR_AUTO,
), g_settings=AppFlags(
    (empty),
)
DEBUG:clap:Parser::propagate_settings: self=b, g_settings=AppFlags(
    SC_REQUIRED_ELSE_HELP,
)
DEBUG:clap:Parser::get_matches_with;
DEBUG:clap:Parser::create_help_and_version;
DEBUG:clap:Parser::create_help_and_version: Building --help
DEBUG:clap:Parser::create_help_and_version: Building --version
DEBUG:clap:Parser::create_help_and_version: Building help
DEBUG:clap:Parser::get_matches_with: Begin parsing '"a"' ([97])
DEBUG:clap:Parser::is_new_arg:"a":NotFound
DEBUG:clap:Parser::is_new_arg: arg_allows_tac=false
DEBUG:clap:Parser::is_new_arg: probably value
DEBUG:clap:Parser::is_new_arg: starts_new_arg=false
DEBUG:clap:Parser::possible_subcommand: arg="a"
DEBUG:clap:Parser::get_matches_with: possible_sc=true, sc=Some("a")
DEBUG:clap:Parser::parse_subcommand;
DEBUG:clap:usage::get_required_usage_from: reqs=[], extra=None
DEBUG:clap:usage::get_required_usage_from: after init desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: no more children
DEBUG:clap:usage::get_required_usage_from: final desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: args_in_groups=[]
DEBUG:clap:Parser::parse_subcommand: About to parse sc=a
DEBUG:clap:Parser::parse_subcommand: sc settings=AppFlags(
    SC_REQUIRED_ELSE_HELP | NEEDS_LONG_HELP | NEEDS_LONG_VERSION | NEEDS_SC_HELP | UTF8_NONE | COLOR_AUTO,
)
DEBUG:clap:Parser::get_matches_with;
DEBUG:clap:Parser::create_help_and_version;
DEBUG:clap:Parser::create_help_and_version: Building --help
DEBUG:clap:Parser::create_help_and_version: Building --version
DEBUG:clap:Parser::create_help_and_version: Building help
DEBUG:clap:Parser::get_matches_with: Begin parsing '"b"' ([98])
DEBUG:clap:Parser::is_new_arg:"b":NotFound
DEBUG:clap:Parser::is_new_arg: arg_allows_tac=false
DEBUG:clap:Parser::is_new_arg: probably value
DEBUG:clap:Parser::is_new_arg: starts_new_arg=false
DEBUG:clap:Parser::possible_subcommand: arg="b"
DEBUG:clap:Parser::get_matches_with: possible_sc=true, sc=Some("b")
DEBUG:clap:Parser::parse_subcommand;
DEBUG:clap:usage::get_required_usage_from: reqs=[], extra=None
DEBUG:clap:usage::get_required_usage_from: after init desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: no more children
DEBUG:clap:usage::get_required_usage_from: final desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: args_in_groups=[]
DEBUG:clap:Parser::parse_subcommand: About to parse sc=b
DEBUG:clap:Parser::parse_subcommand: sc settings=AppFlags(
    SC_REQUIRED_ELSE_HELP | NEEDS_LONG_HELP | NEEDS_LONG_VERSION | NEEDS_SC_HELP | UTF8_NONE | COLOR_AUTO,
)
DEBUG:clap:Parser::get_matches_with;
DEBUG:clap:Parser::create_help_and_version;
DEBUG:clap:Parser::create_help_and_version: Building --help
DEBUG:clap:Parser::create_help_and_version: Building --version
DEBUG:clap:Parser::get_matches_with: SubcommandRequiredElseHelp=true
DEBUG:clap:Help::write_parser_help;
DEBUG:clap:Help::write_parser_help;
DEBUG:clap:Parser::color;
DEBUG:clap:Parser::color: Color setting...Auto
DEBUG:clap:is_a_tty: stderr=true
DEBUG:clap:Help::new;
DEBUG:clap:Help::write_help;
DEBUG:clap:Help::write_default_help;
DEBUG:clap:Help::write_bin_name;
DEBUG:clap:Help::write_version;
DEBUG:clap:Help::write_default_help: writing about
DEBUG:clap:usage::create_usage_no_title;
DEBUG:clap:usage::get_required_usage_from: reqs=[], extra=None
DEBUG:clap:usage::get_required_usage_from: after init desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: no more children
DEBUG:clap:usage::get_required_usage_from: final desc_reqs=[]
DEBUG:clap:usage::get_required_usage_from: args_in_groups=[]
DEBUG:clap:usage::needs_flags_tag;
DEBUG:clap:usage::needs_flags_tag:iter: f=hclap_help;
DEBUG:clap:usage::needs_flags_tag:iter: f=vclap_version;
DEBUG:clap:usage::needs_flags_tag: [FLAGS] not required
DEBUG:clap:usage::create_help_usage: usage=foo a b
DEBUG:clap:Help::write_all_args;
DEBUG:clap:Help::write_args;
DEBUG:clap:Help::write_args: Current Longest...2
DEBUG:clap:Help::write_args: New Longest...6
DEBUG:clap:Help::write_args: Current Longest...6
DEBUG:clap:Help::write_args: New Longest...9
DEBUG:clap:Help::write_arg;
DEBUG:clap:Help::short;
DEBUG:clap:Help::long;
DEBUG:clap:Help::val: arg=--help
DEBUG:clap:Help::spec_vals: a=--help
DEBUG:clap:Help::val: Has switch...Yes
DEBUG:clap:Help::val: force_next_line...false
DEBUG:clap:Help::val: nlh...false
DEBUG:clap:Help::val: taken...21
DEBUG:clap:Help::val: help_width > (width - taken)...23 > (120 - 21)
DEBUG:clap:Help::val: longest...9
DEBUG:clap:Help::val: next_line...No
DEBUG:clap:write_spaces!: num=7
DEBUG:clap:Help::help;
DEBUG:clap:Help::help: Next Line...false
DEBUG:clap:Help::help: Too long...No
DEBUG:clap:Help::write_arg;
DEBUG:clap:Help::short;
DEBUG:clap:Help::long;
DEBUG:clap:Help::val: arg=--version
DEBUG:clap:Help::spec_vals: a=--version
DEBUG:clap:Help::val: Has switch...Yes
DEBUG:clap:Help::val: force_next_line...false
DEBUG:clap:Help::val: nlh...false
DEBUG:clap:Help::val: taken...21
DEBUG:clap:Help::val: help_width > (width - taken)...26 > (120 - 21)
DEBUG:clap:Help::val: longest...9
DEBUG:clap:Help::val: next_line...No
DEBUG:clap:write_spaces!: num=4
DEBUG:clap:Help::help;
DEBUG:clap:Help::help: Next Line...false
DEBUG:clap:Help::help: Too long...No
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant