Merge pull request #1096 from kbknapp/issues-1093,1095

Issues 1093,1095
This commit is contained in:
Kevin K 2017-11-06 21:48:07 -05:00 committed by GitHub
commit 38fe447292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 2 deletions

View file

@ -1,4 +1,5 @@
// Std
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;
use std::ops::BitOr;

View file

@ -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 ");

View file

@ -1,4 +1,5 @@
// Std
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;

View file

@ -1,3 +1,4 @@
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;
use std::fmt;

View file

@ -1,6 +1,7 @@
// Std
use std::io::Write;
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
// Internal

View file

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

View file

@ -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));
}

View file

@ -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));
}