-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Make sure you completed the following tasks
- Searched the discussions
- Searched the closes issues
Code
$ cargo new generate-panic
$ cd generate-panic
$ cat <<EOF >>Cargo.toml
clap = "3.0.0-beta.1"
clap_generate = "3.0.0-beta.1"
EOFuse clap::{Clap, FromArgMatches, IntoApp};
use clap_generate::{generate, generators::Bash};
#[derive(Clap)]
enum Command {
Generate,
}
#[derive(Clap)]
struct Arguments {
#[clap(subcommand)]
command: Command,
}
fn main() {
let mut app = Arguments::into_app();
let Arguments { command: _c, } = Arguments::from_arg_matches(&app.get_matches_mut());
for sc in app.get_subcommands() {
println!(
"name: '{}' bin_name: {:?}",
sc.get_name(),
sc.get_bin_name()
);
}
let bin_name = app.get_bin_name().unwrap().to_owned();
generate::<Bash, _>(&mut app, bin_name, &mut std::io::stdout());
}Steps to reproduce the issue
- Run
cargo run generate - The following panic is produced:
Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/generate-panic generate`name: 'generate' bin_name: Some("generate-panic generate")
name: 'help' bin_name: None
thread 'main' panicked at 'calledOption::unwrap()on aNonevalue', /Users/cpick/.cargo/registry/src/github.com-1ecc6299db9ec823/clap_generate-3.0.0-beta.1/src/generators/mod.rs:105:31
note: run withRUST_BACKTRACE=1environment variable to display a backtrace
Version
- Rust: rustc 1.44.1 (c7087fe00 2020-06-17)
- Clap: 3.0.0-beta.1 for
clapandclap_generate, I have also reproduced with the currentmaster(d8fccdb)
Actual Behavior Summary
Attempting to generate bash completions by running the code above as described in the "steps to reproduce" section causes a panic when trying to call sc.get_bin_name().unwrap() on any subcommand other than the one that was run (in the case of the example, the auto-generated help command).
The code above prints all the subcommands bin names and helps is None.
Expected Behavior Summary
I expected bash completions to be generated.
Additional context
None that I can think of.
Debug output
Compile clap with debug feature:
[dependencies]
clap = { version = "*", features = ["debug"] }The output may be very long, so feel free to link to a gist or attach a text file
Debug Output
[Running 'cargo run generate']
Compiling clap_derive v3.0.0-beta.1
Compiling clap v3.0.0-beta.1
Compiling clap_generate v3.0.0-beta.1
Compiling generate-panic v0.1.0 (/Users/cpick/src/generate-panic)
Finished dev [unoptimized + debuginfo] target(s) in 9.86s
Running target/debug/generate-panic generate
[ clap::build::app] App::_do_parse
[ clap::build::app] App::_build
[ clap::build::app] App::_derive_display_order:generate-panic
[ clap::build::app] App::_derive_display_order:generate
[ clap::build::app] App::_create_help_and_version
[ clap::build::app] App::_create_help_and_version: Building --help
[ clap::build::app] App::_create_help_and_version: Building --version
[ clap::build::app] App::_create_help_and_version: Building help
[ clap::build::app] App::_debug_asserts
[ clap::build::arg] Arg::_debug_asserts:help
[ clap::build::arg] Arg::_debug_asserts:version
[ clap::parse::parser] Parser::get_matches_with
[ clap::parse::parser] Parser::_build
[ clap::parse::parser] Parser::_verify_positionals
[ clap::parse::parser] Parser::get_matches_with: Begin parsing '"generate"' ([103, 101, 110, 101, 114, 97, 116, 101])
[ clap::parse::parser] Parser::is_new_arg: "generate":NotFound
[ clap::parse::parser] Parser::is_new_arg: arg_allows_tac=false
[ clap::parse::parser] Parser::is_new_arg: probably value
[ clap::parse::parser] Parser::is_new_arg: starts_new_arg=false
[ clap::parse::parser] Parser::possible_subcommand: arg="generate"
[ clap::parse::parser] Parser::get_matches_with: possible_sc=true, sc=Some("generate")
[ clap::parse::parser] Parser::parse_subcommand
[ clap::output::usage] Usage::get_required_usage_from: incls=[], matcher=false, incl_last=true
[ clap::output::usage] Usage::get_required_usage_from: ret_val=[]
[ clap::build::app] App::_propagate:generate-panic
[ clap::build::app] App::_build
[ clap::build::app] App::_derive_display_order:generate
[ clap::build::app] App::_create_help_and_version
[ clap::build::app] App::_create_help_and_version: Building --help
[ clap::build::app] App::_create_help_and_version: Building --version
[ clap::build::app] App::_debug_asserts
[ clap::build::arg] Arg::_debug_asserts:help
[ clap::build::arg] Arg::_debug_asserts:version
[ clap::parse::parser] Parser::parse_subcommand: About to parse sc=generate
[ clap::parse::parser] Parser::get_matches_with
[ clap::parse::parser] Parser::_build
[ clap::parse::parser] Parser::_verify_positionals
[ clap::parse::parser] Parser::remove_overrides
[ clap::parse::validator] Validator::validate
[ clap::parse::parser] Parser::add_defaults
[ clap::parse::validator] Validator::validate_conflicts
[ clap::parse::validator] Validator::validate_exclusive
[ clap::parse::validator] Validator::gather_conflicts
[ clap::parse::validator] Validator::validate_required: required=ChildGraph([])
[ clap::parse::validator] Validator::gather_requirements
[ clap::parse::validator] Validator::validate_required_unless
[ clap::parse::validator] Validator::validate_matched_args
[ clap::parse::parser] Parser::remove_overrides
[ clap::parse::validator] Validator::validate
[ clap::parse::parser] Parser::add_defaults
[ clap::parse::validator] Validator::validate_conflicts
[ clap::parse::validator] Validator::validate_exclusive
[ clap::parse::validator] Validator::gather_conflicts
[ clap::parse::validator] Validator::validate_required: required=ChildGraph([])
[ clap::parse::validator] Validator::gather_requirements
[ clap::parse::validator] Validator::validate_required_unless
[ clap::parse::validator] Validator::validate_matched_args
[ clap::parse::arg_matcher] ArgMatcher::get_global_values: global_arg_vec=[]
name: 'generate' bin_name: Some("generate-panic generate")
name: 'help' bin_name: None
[clap_generate::generators::shells::bash] all_options_for_path: path=generate-panic
[ clap_generate::generators] subcommands: name=generate-panic
[ clap_generate::generators] subcommands: Has subcommands...true
[ clap_generate::generators] subcommands:iter: name=generate, bin_name=generate-panic generate
thread 'main' panicked at 'called Option::unwrap() on a None value', /Users/cpick/.cargo/registry/src/github.com-1ecc6299db9ec823/clap_generate-3.0.0-beta.1/src/generators/mod.rs:105:31
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[Finished running. Exit status: 101]