Skip to content

the --version flag concatenates subcommands #1382

Open
@Geal

Description

Maintainer's notes


Rust Version

rustc 1.31.0-nightly (4bd4e4130 2018-10-25)

Affected Version of clap

2.32.0

Bug or Feature Request Summary

Passing the --version flag after one or more subcommands should not append the subcommand names to the process name

Expected Behavior Summary

$ ./target/debug/clap-test --version
claptest 1.0
$ ./target/debug/clap-test test --version
claptest 1.0
$ ./target/debug/clap-test test hello --version
claptest 1.0

Actual Behavior Summary

$ ./target/debug/clap-test --version
claptest 1.0
$ ./target/debug/clap-test test --version
clap-test-test 
$ ./target/debug/clap-test test hello --version
clap-test-test-hello

Sample Code or Link to Sample Code

extern crate clap;
use clap::{Arg, App, SubCommand};

fn main() {
	let matches = App::new("claptest")
		.version("1.0")
		.arg(Arg::with_name("config")
				 .short("c")
				 .long("config")
				 .value_name("FILE")
				 .help("Sets a custom config file")
				 .takes_value(true))
		.subcommand(SubCommand::with_name("test")
								.help("print debug information verbosely")
								.subcommand(SubCommand::with_name("hello")
														.help("hello")))
		.get_matches();
}

Debug output

Compile clap with cargo features "debug" such as:

[dependencies]
clap = { version = "2", features = ["debug"] }

Output for: ./target/debug/clap-test test --version:

Debug Output

DEBUG:clap:Parser::add_subcommand: term_w=None, name=hello
DEBUG:clap:Parser::add_subcommand: term_w=None, name=test
DEBUG:clap:Parser::propagate_settings: self=claptest, g_settings=AppFlags(
(empty)
)
DEBUG:clap:Parser::propagate_settings: sc=test, 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=test, g_settings=AppFlags(
(empty)
)
DEBUG:clap:Parser::propagate_settings: sc=hello, 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=hello, g_settings=AppFlags(
(empty)
)
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 '"test"' ([116, 101, 115, 116])
DEBUG:clap:Parser::is_new_arg:"test":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="test"
DEBUG:clap:Parser::get_matches_with: possible_sc=true, sc=Some("test")
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=test
DEBUG:clap:Parser::parse_subcommand: sc settings=AppFlags(
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 '"--version"' ([45, 45, 118, 101, 114, 115, 105, 111, 110])
DEBUG:clap:Parser::is_new_arg:"--version":NotFound
DEBUG:clap:Parser::is_new_arg: arg_allows_tac=false
DEBUG:clap:Parser::is_new_arg: -- found
DEBUG:clap:Parser::is_new_arg: starts_new_arg=true
DEBUG:clap:Parser::possible_subcommand: arg="--version"
DEBUG:clap:Parser::get_matches_with: possible_sc=false, sc=None
DEBUG:clap:ArgMatcher::process_arg_overrides:None;
DEBUG:clap:Parser::parse_long_arg;
DEBUG:clap:Parser::parse_long_arg: Does it contain '='...No
DEBUG:clap:Parser::parse_long_arg: Found valid flag '--version'
DEBUG:clap:Parser::check_for_help_and_version_str;
DEBUG:clap:Parser::check_for_help_and_version_str: Checking if --version is help or version...Version
DEBUG:clap:Parser::_version:
clap-test-test

this does not look like a critical bug, but it still feels weird :)

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...C-bugCategory: Updating dependenciesS-blockedStatus: Blocked on something else such as an RFC or other implementation work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions