mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
Merge pull request #1096 from kbknapp/issues-1093,1095
Issues 1093,1095
This commit is contained in:
commit
38fe447292
8 changed files with 36 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
// Std
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
use std::ascii::AsciiExt;
|
||||
use std::str::FromStr;
|
||||
use std::ops::BitOr;
|
||||
|
|
|
@ -96,7 +96,7 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
|
|||
// supporting multiple values
|
||||
if p.opts.iter().any(|o| o.is_set(ArgSettings::Multiple)) &&
|
||||
p.positionals.values().any(|p| !p.is_set(ArgSettings::Required)) &&
|
||||
!p.has_visible_subcommands() && !has_last {
|
||||
!(p.has_visible_subcommands() || p.is_set(AS::AllowExternalSubcommands)) && !has_last {
|
||||
usage.push_str(" [--]");
|
||||
}
|
||||
let not_req_or_hidden =
|
||||
|
@ -131,7 +131,7 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
|
|||
}
|
||||
|
||||
// incl_reqs is only false when this function is called recursively
|
||||
if p.has_visible_subcommands() && incl_reqs {
|
||||
if p.has_visible_subcommands() && incl_reqs || p.is_set(AS::AllowExternalSubcommands) {
|
||||
if p.is_set(AS::SubcommandsNegateReqs) || p.is_set(AS::ArgsNegateSubcommands) {
|
||||
if !p.is_set(AS::ArgsNegateSubcommands) {
|
||||
usage.push_str("\n ");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// Std
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
use std::ascii::AsciiExt;
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#[cfg(not(feature = "nightly"))]
|
||||
use std::ascii::AsciiExt;
|
||||
use std::str::FromStr;
|
||||
use std::fmt;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
// Std
|
||||
use std::io::Write;
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
use std::ascii::AsciiExt;
|
||||
|
||||
// Internal
|
||||
|
|
|
@ -308,6 +308,7 @@ macro_rules! arg_enum {
|
|||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> ::std::result::Result<Self,Self::Err> {
|
||||
#[cfg(not(feature = "nightly"))]
|
||||
use ::std::ascii::AsciiExt;
|
||||
match s {
|
||||
$(stringify!($v) |
|
||||
|
|
|
@ -5,6 +5,15 @@ use clap::{App, Arg, SubCommand, AppSettings, ErrorKind};
|
|||
|
||||
include!("../clap-test.rs");
|
||||
|
||||
static ALLOW_EXT_SC: &'static str = "clap-test v1.4.8
|
||||
|
||||
USAGE:
|
||||
clap-test [SUBCOMMAND]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-V, --version Prints version information";
|
||||
|
||||
static DONT_COLLAPSE_ARGS: &'static str = "clap-test v1.4.8
|
||||
|
||||
USAGE:
|
||||
|
@ -651,4 +660,12 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_option() {
|
|||
|
||||
assert!(res.is_err());
|
||||
assert_eq!(res.unwrap_err().kind, ErrorKind::UnknownArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1093_allow_ext_sc() {
|
||||
let app = App::new("clap-test")
|
||||
.version("v1.4.8")
|
||||
.setting(AppSettings::AllowExternalSubcommands);
|
||||
assert!(test::compare_output(app, "clap-test --help", ALLOW_EXT_SC, false));
|
||||
}
|
|
@ -147,3 +147,15 @@ fn quoted_arg_name() {
|
|||
.expect("Expected to successfully match the given args.");
|
||||
assert!(matches.is_present("option2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arg_enum() {
|
||||
arg_enum!{
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum Greek {
|
||||
Alpha,
|
||||
Bravo
|
||||
}
|
||||
}
|
||||
assert_eq!("Alpha".parse::<Greek>(), Ok(Greek::Alpha));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue