mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Auto merge of #681 - tormol:fix_werrnings, r=kbknapp
Fix warnings in code enabled by yaml, !color or !suggestions
This commit is contained in:
commit
95bde36353
8 changed files with 25 additions and 30 deletions
|
@ -57,7 +57,7 @@ mod test {
|
|||
|
||||
// Now we check the output of print_help()
|
||||
let mut help = vec![];
|
||||
sc.write_help(&mut help).ok().expect("failed to print help");
|
||||
sc.write_help(&mut help).expect("failed to print help");
|
||||
assert_eq!(str::from_utf8(&help).unwrap(), out);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ mod test {
|
|||
|
||||
// Now we check the output of print_help()
|
||||
let mut help = vec![];
|
||||
a.write_help(&mut help).ok().expect("failed to print help");
|
||||
a.write_help(&mut help).expect("failed to print help");
|
||||
assert_eq!(str::from_utf8(&help).unwrap(), out);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ mod test {
|
|||
|
||||
// Now we check the output of print_version()
|
||||
let mut ver = vec![];
|
||||
a.write_version(&mut ver).ok().expect("failed to print help");
|
||||
a.write_version(&mut ver).expect("failed to print help");
|
||||
assert_eq!(str::from_utf8(&ver).unwrap(), out);
|
||||
}
|
||||
|
||||
|
|
|
@ -1013,7 +1013,7 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
/// use std::io;
|
||||
/// let mut app = App::new("myprog");
|
||||
/// let mut out = io::stdout();
|
||||
/// app.write_help(&mut out).ok().expect("failed to write to stdout");
|
||||
/// app.write_help(&mut out).expect("failed to write to stdout");
|
||||
/// ```
|
||||
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||
pub fn write_help<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
||||
|
@ -1029,7 +1029,7 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
/// use std::io;
|
||||
/// let mut app = App::new("myprog");
|
||||
/// let mut out = io::stdout();
|
||||
/// app.write_version(&mut out).ok().expect("failed to write to stdout");
|
||||
/// app.write_version(&mut out).expect("failed to write to stdout");
|
||||
/// ```
|
||||
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||
pub fn write_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
||||
|
@ -1422,16 +1422,14 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
|||
a = a.setting(s.parse().expect("unknown AppSetting found in YAML file"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(v) = yaml["settings"].as_str() {
|
||||
a = a.setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||
} else if yaml["settings"] != Yaml::BadValue {
|
||||
panic!("Failed to convert YAML value {:?} to a string",
|
||||
yaml["settings"]);
|
||||
}
|
||||
} else if let Some(v) = yaml["settings"].as_str() {
|
||||
a = a.setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||
} else if yaml["settings"] != Yaml::BadValue {
|
||||
panic!("Failed to convert YAML value {:?} to a string",
|
||||
yaml["settings"]);
|
||||
}
|
||||
if let Some(v) = yaml["global_setting"].as_str() {
|
||||
a = a.setting(v.parse().ok().expect("unknown AppSetting found in YAML file"));
|
||||
a = a.setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||
} else if yaml["global_setting"] != Yaml::BadValue {
|
||||
panic!("Failed to convert YAML value {:?} to an AppSetting",
|
||||
yaml["setting"]);
|
||||
|
@ -1440,17 +1438,14 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
|||
for ys in v {
|
||||
if let Some(s) = ys.as_str() {
|
||||
a = a.global_setting(s.parse()
|
||||
.ok()
|
||||
.expect("unknown AppSetting found in YAML file"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(v) = yaml["global_settings"].as_str() {
|
||||
a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||
} else if yaml["global_settings"] != Yaml::BadValue {
|
||||
panic!("Failed to convert YAML value {:?} to a string",
|
||||
yaml["global_settings"]);
|
||||
}
|
||||
} else if let Some(v) = yaml["global_settings"].as_str() {
|
||||
a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||
} else if yaml["global_settings"] != Yaml::BadValue {
|
||||
panic!("Failed to convert YAML value {:?} to a string",
|
||||
yaml["global_settings"]);
|
||||
}
|
||||
|
||||
macro_rules! vec_or_str {
|
||||
|
@ -1481,12 +1476,12 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
|||
|
||||
if let Some(v) = yaml["args"].as_vec() {
|
||||
for arg_yaml in v {
|
||||
a = a.arg(Arg::from_yaml(&arg_yaml.as_hash().unwrap()));
|
||||
a = a.arg(Arg::from_yaml(arg_yaml.as_hash().unwrap()));
|
||||
}
|
||||
}
|
||||
if let Some(v) = yaml["subcommands"].as_vec() {
|
||||
for sc_yaml in v {
|
||||
a = a.subcommand(SubCommand::from_yaml(&sc_yaml));
|
||||
a = a.subcommand(SubCommand::from_yaml(sc_yaml));
|
||||
}
|
||||
}
|
||||
if let Some(v) = yaml["groups"].as_vec() {
|
||||
|
|
|
@ -141,7 +141,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```
|
||||
/// [`Arg`]: ./struct.Arg.html
|
||||
#[cfg(feature = "yaml")]
|
||||
pub fn from_yaml<'y>(y: &'y BTreeMap<Yaml, Yaml>) -> Arg<'y, 'y> {
|
||||
pub fn from_yaml(y: &BTreeMap<Yaml, Yaml>) -> Arg {
|
||||
// We WANT this to panic on error...so expect() is good.
|
||||
let name_yml = y.keys().nth(0).unwrap();
|
||||
let name_str = name_yml.as_str().unwrap();
|
||||
|
|
|
@ -62,7 +62,7 @@ impl<'a> SubCommand<'a> {
|
|||
/// let sc = SubCommand::from_yaml(sc_yaml);
|
||||
/// ```
|
||||
#[cfg(feature = "yaml")]
|
||||
pub fn from_yaml<'y>(yaml: &'y Yaml) -> App<'y, 'y> {
|
||||
pub fn from_yaml(yaml: &Yaml) -> App {
|
||||
App::from_yaml(yaml)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ const STDERR: i32 = libc::STDERR_FILENO;
|
|||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
const STDOUT: i32 = libc::STDOUT_FILENO;
|
||||
|
||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||
#[cfg(target_os = "windows")]
|
||||
const STDERR: i32 = 0;
|
||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||
#[cfg(target_os = "windows")]
|
||||
const STDOUT: i32 = 0;
|
||||
|
||||
#[doc(hidden)]
|
||||
|
@ -127,6 +127,7 @@ impl<T: AsRef<str>> Format<T> {
|
|||
}
|
||||
|
||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||
#[allow(match_same_arms)]
|
||||
impl<T: fmt::Display> Format<T> {
|
||||
fn format(&self) -> &T {
|
||||
match *self {
|
||||
|
|
|
@ -88,7 +88,7 @@ fn unified_help() {
|
|||
|
||||
// Now we check the output of print_help()
|
||||
let mut help = vec![];
|
||||
app.write_help(&mut help).ok().expect("failed to print help");
|
||||
app.write_help(&mut help).expect("failed to print help");
|
||||
assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\
|
||||
Kevin K.
|
||||
tests stuff
|
||||
|
|
|
@ -16,7 +16,7 @@ fn hidden_args() {
|
|||
|
||||
// Now we check the output of print_help()
|
||||
let mut help = vec![];
|
||||
app.write_help(&mut help).ok().expect("failed to print help");
|
||||
app.write_help(&mut help).expect("failed to print help");
|
||||
assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\
|
||||
Kevin K.
|
||||
tests stuff
|
||||
|
|
|
@ -115,7 +115,6 @@ arg_enum!{
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(feature = "lints", allow(single_match))]
|
||||
fn test_enums() {
|
||||
let v1_lower = "valone";
|
||||
let v1_camel = "ValOne";
|
||||
|
|
Loading…
Reference in a new issue