mirror of
https://github.com/clap-rs/clap
synced 2025-01-07 10:18:48 +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()
|
// Now we check the output of print_help()
|
||||||
let mut help = vec![];
|
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);
|
assert_eq!(str::from_utf8(&help).unwrap(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ mod test {
|
||||||
|
|
||||||
// Now we check the output of print_help()
|
// Now we check the output of print_help()
|
||||||
let mut help = vec![];
|
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);
|
assert_eq!(str::from_utf8(&help).unwrap(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ mod test {
|
||||||
|
|
||||||
// Now we check the output of print_version()
|
// Now we check the output of print_version()
|
||||||
let mut ver = vec![];
|
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);
|
assert_eq!(str::from_utf8(&ver).unwrap(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
/// use std::io;
|
/// use std::io;
|
||||||
/// let mut app = App::new("myprog");
|
/// let mut app = App::new("myprog");
|
||||||
/// let mut out = io::stdout();
|
/// 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
|
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||||
pub fn write_help<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
pub fn write_help<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
||||||
|
@ -1029,7 +1029,7 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
/// use std::io;
|
/// use std::io;
|
||||||
/// let mut app = App::new("myprog");
|
/// let mut app = App::new("myprog");
|
||||||
/// let mut out = io::stdout();
|
/// 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
|
/// [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||||
pub fn write_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {
|
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"));
|
a = a.setting(s.parse().expect("unknown AppSetting found in YAML file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(v) = yaml["settings"].as_str() {
|
||||||
if let Some(v) = yaml["settings"].as_str() {
|
a = a.setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||||
a = a.setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
} else if yaml["settings"] != Yaml::BadValue {
|
||||||
} else if yaml["settings"] != Yaml::BadValue {
|
panic!("Failed to convert YAML value {:?} to a string",
|
||||||
panic!("Failed to convert YAML value {:?} to a string",
|
yaml["settings"]);
|
||||||
yaml["settings"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if let Some(v) = yaml["global_setting"].as_str() {
|
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 {
|
} else if yaml["global_setting"] != Yaml::BadValue {
|
||||||
panic!("Failed to convert YAML value {:?} to an AppSetting",
|
panic!("Failed to convert YAML value {:?} to an AppSetting",
|
||||||
yaml["setting"]);
|
yaml["setting"]);
|
||||||
|
@ -1440,17 +1438,14 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> {
|
||||||
for ys in v {
|
for ys in v {
|
||||||
if let Some(s) = ys.as_str() {
|
if let Some(s) = ys.as_str() {
|
||||||
a = a.global_setting(s.parse()
|
a = a.global_setting(s.parse()
|
||||||
.ok()
|
|
||||||
.expect("unknown AppSetting found in YAML file"));
|
.expect("unknown AppSetting found in YAML file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(v) = yaml["global_settings"].as_str() {
|
||||||
if let Some(v) = yaml["global_settings"].as_str() {
|
a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
||||||
a = a.global_setting(v.parse().expect("unknown AppSetting found in YAML file"));
|
} else if yaml["global_settings"] != Yaml::BadValue {
|
||||||
} else if yaml["global_settings"] != Yaml::BadValue {
|
panic!("Failed to convert YAML value {:?} to a string",
|
||||||
panic!("Failed to convert YAML value {:?} to a string",
|
yaml["global_settings"]);
|
||||||
yaml["global_settings"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! vec_or_str {
|
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() {
|
if let Some(v) = yaml["args"].as_vec() {
|
||||||
for arg_yaml in v {
|
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() {
|
if let Some(v) = yaml["subcommands"].as_vec() {
|
||||||
for sc_yaml in v {
|
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() {
|
if let Some(v) = yaml["groups"].as_vec() {
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
||||||
/// ```
|
/// ```
|
||||||
/// [`Arg`]: ./struct.Arg.html
|
/// [`Arg`]: ./struct.Arg.html
|
||||||
#[cfg(feature = "yaml")]
|
#[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.
|
// We WANT this to panic on error...so expect() is good.
|
||||||
let name_yml = y.keys().nth(0).unwrap();
|
let name_yml = y.keys().nth(0).unwrap();
|
||||||
let name_str = name_yml.as_str().unwrap();
|
let name_str = name_yml.as_str().unwrap();
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl<'a> SubCommand<'a> {
|
||||||
/// let sc = SubCommand::from_yaml(sc_yaml);
|
/// let sc = SubCommand::from_yaml(sc_yaml);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "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)
|
App::from_yaml(yaml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ const STDERR: i32 = libc::STDERR_FILENO;
|
||||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||||
const STDOUT: i32 = libc::STDOUT_FILENO;
|
const STDOUT: i32 = libc::STDOUT_FILENO;
|
||||||
|
|
||||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
#[cfg(target_os = "windows")]
|
||||||
const STDERR: i32 = 0;
|
const STDERR: i32 = 0;
|
||||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
#[cfg(target_os = "windows")]
|
||||||
const STDOUT: i32 = 0;
|
const STDOUT: i32 = 0;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -127,6 +127,7 @@ impl<T: AsRef<str>> Format<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||||
|
#[allow(match_same_arms)]
|
||||||
impl<T: fmt::Display> Format<T> {
|
impl<T: fmt::Display> Format<T> {
|
||||||
fn format(&self) -> &T {
|
fn format(&self) -> &T {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn unified_help() {
|
||||||
|
|
||||||
// Now we check the output of print_help()
|
// Now we check the output of print_help()
|
||||||
let mut help = vec![];
|
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\
|
assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\
|
||||||
Kevin K.
|
Kevin K.
|
||||||
tests stuff
|
tests stuff
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn hidden_args() {
|
||||||
|
|
||||||
// Now we check the output of print_help()
|
// Now we check the output of print_help()
|
||||||
let mut help = vec![];
|
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\
|
assert_eq!(&*String::from_utf8_lossy(&*help), &*String::from("test 1.3\n\
|
||||||
Kevin K.
|
Kevin K.
|
||||||
tests stuff
|
tests stuff
|
||||||
|
|
|
@ -115,7 +115,6 @@ arg_enum!{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(feature = "lints", allow(single_match))]
|
|
||||||
fn test_enums() {
|
fn test_enums() {
|
||||||
let v1_lower = "valone";
|
let v1_lower = "valone";
|
||||||
let v1_camel = "ValOne";
|
let v1_camel = "ValOne";
|
||||||
|
|
Loading…
Reference in a new issue