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

the --version flag concatenates subcommands #108

Open
epage opened this issue Dec 6, 2021 · 1 comment
Open

the --version flag concatenates subcommands #108

epage opened this issue Dec 6, 2021 · 1 comment

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by Geal
Thursday Nov 15, 2018 at 09:05 GMT
Originally opened as clap-rs/clap#1382


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 :)

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by EverlastingBugstopper
Monday Oct 28, 2019 at 22:19 GMT


+1 on this. Thought we had a bug in our implementation but it seems to be the way clap handles versions for subcommands. It can be overridden with a .version on each subcommand, but my feeling is that it should default to the parent's version. cloudflare/wrangler-legacy#791

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