diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..a8849e93 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,31 @@ +Please use the following template to assist with creating an issue, and getting a speedy resolution. If an area is not aplicable, feel free to delete the area, or mark with `N/A` + +### Rust Version + +* Use the output of `rustc -V` + +### Affected Version of clap + +* Can be found in Cargo.lock of your project (i.e. `grep clap Cargo.lock`) + +### Expected Behavior Summary + + +### Actual Behavior Summary + + +### Steps to Reproduce the issue + + +### Sample Code or Link to Sample Code + + +### Debug output + +Compile clap with cargo features `"debug"` such as: + +```toml +[dependencies] +clap = { version = "2", features = ["debug"] } +``` +The output may be very long, so feel free to link to a gist or attach a text file diff --git a/src/app/help.rs b/src/app/help.rs index 63b5ef8d..3270f0cc 100644 --- a/src/app/help.rs +++ b/src/app/help.rs @@ -169,9 +169,9 @@ impl<'a> Help<'a> { if let Some(h) = parser.meta.help_str { write!(self.writer, "{}", h).map_err(Error::from)?; } else if let Some(tmpl) = parser.meta.template { - self.write_templated_help(parser, tmpl)?; + try!(self.write_templated_help(&parser, tmpl)); } else { - self.write_default_help(parser)?; + try!(self.write_default_help(&parser)); } Ok(()) } @@ -201,9 +201,9 @@ impl<'a> Help<'a> { if first { first = false; } else { - self.writer.write(b"\n")?; + try!(self.writer.write(b"\n")); } - self.write_arg(arg.as_base())?; + try!(self.write_arg(arg.as_base())); } Ok(()) } @@ -237,9 +237,9 @@ impl<'a> Help<'a> { if first { first = false; } else { - self.writer.write(b"\n")?; + try!(self.writer.write(b"\n")); } - self.write_arg(arg.as_base())?; + try!(self.write_arg(arg.as_base())); } } Ok(()) @@ -248,17 +248,17 @@ impl<'a> Help<'a> { /// Writes help for an argument to the wrapped stream. fn write_arg<'b, 'c>(&mut self, arg: &ArgWithDisplay<'b, 'c>) -> io::Result<()> { debugln!("fn=write_arg;"); - self.short(arg)?; - self.long(arg)?; - let spec_vals = self.val(arg)?; - self.help(arg, &*spec_vals)?; + try!(self.short(arg)); + try!(self.long(arg)); + let spec_vals = try!(self.val(arg)); + try!(self.help(arg, &*spec_vals)); Ok(()) } /// Writes argument's short command to the wrapped stream. fn short<'b, 'c>(&mut self, arg: &ArgWithDisplay<'b, 'c>) -> io::Result<()> { debugln!("fn=short;"); - write!(self.writer, "{}", TAB)?; + try!(write!(self.writer, "{}", TAB)); if let Some(s) = arg.short() { color!(self, "-{}", s, good) } else if arg.has_switch() { @@ -277,16 +277,16 @@ impl<'a> Help<'a> { if arg.takes_value() { if let Some(l) = arg.long() { if arg.short().is_some() { - write!(self.writer, ", ")?; + try!(write!(self.writer, ", ")); } - color!(self, "--{}", l, good)? + try!(color!(self, "--{}", l, good)) } - write!(self.writer, " ")?; + try!(write!(self.writer, " ")); } else if let Some(l) = arg.long() { if arg.short().is_some() { - write!(self.writer, ", ")?; + try!(write!(self.writer, ", ")); } - color!(self, "--{}", l, good)?; + try!(color!(self, "--{}", l, good)); } Ok(()) } @@ -298,33 +298,33 @@ impl<'a> Help<'a> { if let Some(vec) = arg.val_names() { let mut it = vec.iter().peekable(); while let Some((_, val)) = it.next() { - color!(self, "<{}>", val, good)?; + try!(color!(self, "<{}>", val, good)); if it.peek().is_some() { - write!(self.writer, " ")?; + try!(write!(self.writer, " ")); } } let num = vec.len(); if arg.is_set(ArgSettings::Multiple) && num == 1 { - color!(self, "...", good)?; + try!(color!(self, "...", good)); } } else if let Some(num) = arg.num_vals() { let mut it = (0..num).peekable(); while let Some(_) = it.next() { - color!(self, "<{}>", arg.name(), good)?; + try!(color!(self, "<{}>", arg.name(), good)); if it.peek().is_some() { - write!(self.writer, " ")?; + try!(write!(self.writer, " ")); } } if arg.is_set(ArgSettings::Multiple) && num == 1 { - color!(self, "...", good)?; + try!(color!(self, "...", good)); } } else if arg.has_switch() { - color!(self, "<{}>", arg.name(), good)?; + try!(color!(self, "<{}>", arg.name(), good)); if arg.is_set(ArgSettings::Multiple) { - color!(self, "...", good)?; + try!(color!(self, "...", good)); } } else { - color!(self, "{}", arg, good)?; + try!(color!(self, "{}", arg, good)); } } @@ -414,13 +414,13 @@ impl<'a> Help<'a> { }; if help.contains('\n') { if let Some(part) = help.lines().next() { - write!(self.writer, "{}", part)?; + try!(write!(self.writer, "{}", part)); } for part in help.lines().skip(1) { - write!(self.writer, "\n{}", part)?; + try!(write!(self.writer, "\n{}", part)); } } else { - write!(self.writer, "{}", help)?; + try!(write!(self.writer, "{}", help)); } Ok(()) } @@ -443,7 +443,7 @@ impl<'a> Help<'a> { // Is help on next line, if so then indent if nlh || self.force_next_line { - write!(self.writer, "\n{}{}{}", TAB, TAB, TAB)?; + try!(write!(self.writer, "\n{}{}{}", TAB, TAB, TAB)); } debug!("Too long..."); @@ -481,21 +481,21 @@ impl<'a> Help<'a> { }; if help.contains('\n') { if let Some(part) = help.lines().next() { - write!(self.writer, "{}", part)?; + try!(write!(self.writer, "{}", part)); } for part in help.lines().skip(1) { - write!(self.writer, "\n")?; + try!(write!(self.writer, "\n")); if nlh || self.force_next_line { - write!(self.writer, "{}{}{}", TAB, TAB, TAB)?; + try!(write!(self.writer, "{}{}{}", TAB, TAB, TAB)); } else if arg.has_switch() { write_nspaces!(self.writer, self.longest + 12); } else { write_nspaces!(self.writer, self.longest + 8); } - write!(self.writer, "{}", part)?; + try!(write!(self.writer, "{}", part)); } } else { - write!(self.writer, "{}", help)?; + try!(write!(self.writer, "{}", help)); } Ok(()) } @@ -563,40 +563,41 @@ impl<'a> Help<'a> { let opts_flags = parser.flags() .map(as_arg_trait) .chain(parser.opts().map(as_arg_trait)); - color!(self, "OPTIONS:\n", warning)?; - self.write_args(opts_flags)?; + try!(color!(self, "OPTIONS:\n", warning)); + try!(self.write_args(opts_flags)); first = false; } else { if flags { - color!(self, "FLAGS:\n", warning)?; - self.write_args(parser.flags().map(as_arg_trait))?; + try!(color!(self, "FLAGS:\n", warning)); + try!(self.write_args(parser.flags() + .map(as_arg_trait))); first = false; } if opts { if !first { - self.writer.write(b"\n\n")?; + try!(self.writer.write(b"\n\n")); } - color!(self, "OPTIONS:\n", warning)?; - self.write_args(parser.opts().map(as_arg_trait))?; + try!(color!(self, "OPTIONS:\n", warning)); + try!(self.write_args(parser.opts().map(as_arg_trait))); first = false; } } if pos { if !first { - self.writer.write(b"\n\n")?; + try!(self.writer.write(b"\n\n")); } - color!(self, "ARGS:\n", warning)?; - self.write_args_unsorted(parser.positionals().map(as_arg_trait))?; + try!(color!(self, "ARGS:\n", warning)); + try!(self.write_args_unsorted(parser.positionals().map(as_arg_trait))); first = false; } if subcmds { if !first { - self.writer.write(b"\n\n")?; + try!(self.writer.write(b"\n\n")); } - color!(self, "SUBCOMMANDS:\n", warning)?; - self.write_subcommands(parser)?; + try!(color!(self, "SUBCOMMANDS:\n", warning)); + try!(self.write_subcommands(&parser)); } Ok(()) @@ -620,9 +621,9 @@ impl<'a> Help<'a> { if first { first = false; } else { - self.writer.write(b"\n")?; + try!(self.writer.write(b"\n")); } - self.write_arg(sc)?; + try!(self.write_arg(sc)); } } Ok(()) @@ -630,7 +631,7 @@ impl<'a> Help<'a> { /// Writes version of a Parser Object to the wrapped stream. fn write_version(&mut self, parser: &Parser) -> io::Result<()> { - write!(self.writer, "{}", parser.meta.version.unwrap_or("".into()))?; + try!(write!(self.writer, "{}", parser.meta.version.unwrap_or("".into()))); Ok(()) } @@ -639,12 +640,12 @@ impl<'a> Help<'a> { if let Some(bn) = parser.meta.bin_name.as_ref() { if bn.contains(' ') { // Incase we're dealing with subcommands i.e. git mv is translated to git-mv - color!(self, bn.replace(" ", "-"), good)? + try!(color!(self, bn.replace(" ", "-"), good)) } else { - color!(self, &parser.meta.name[..], good)? + try!(color!(self, &parser.meta.name[..], good)) } } else { - color!(self, &parser.meta.name[..], good)? + try!(color!(self, &parser.meta.name[..], good)) } Ok(()) } @@ -653,27 +654,27 @@ impl<'a> Help<'a> { pub fn write_default_help(&mut self, parser: &Parser) -> ClapResult<()> { debugln!("fn=write_default_help;"); if let Some(h) = parser.meta.pre_help { - self.write_before_after_help(h)?; - self.writer.write(b"\n\n")?; + try!(self.write_before_after_help(h)); + try!(self.writer.write(b"\n\n")); } // Print the version - self.write_bin_name(parser)?; - self.writer.write(b" ")?; - self.write_version(parser)?; - self.writer.write(b"\n")?; + try!(self.write_bin_name(&parser)); + try!(self.writer.write(b" ")); + try!(self.write_version(&parser)); + try!(self.writer.write(b"\n")); if let Some(author) = parser.meta.author { - write!(self.writer, "{}\n", author)?; + try!(write!(self.writer, "{}\n", author)); } if let Some(about) = parser.meta.about { - write!(self.writer, "{}\n", about)?; + try!(write!(self.writer, "{}\n", about)); } - color!(self, "\nUSAGE:", warning)?; - write!(self.writer, - "\n{}{}\n\n", - TAB, - parser.create_usage_no_title(&[]))?; + try!(color!(self, "\nUSAGE:", warning)); + try!(write!(self.writer, + "\n{}{}\n\n", + TAB, + parser.create_usage_no_title(&[]))); let flags = parser.has_flags(); let pos = parser.has_positionals(); @@ -681,14 +682,14 @@ impl<'a> Help<'a> { let subcmds = parser.has_subcommands(); if flags || opts || pos || subcmds { - self.write_all_args(parser)?; + try!(self.write_all_args(&parser)); } if let Some(h) = parser.meta.more_help { if flags || opts || pos || subcmds { - self.writer.write(b"\n\n")?; + try!(self.writer.write(b"\n\n")); } - self.write_before_after_help(h)?; + try!(self.write_before_after_help(h)); } self.writer.flush().map_err(Error::from) @@ -847,65 +848,68 @@ impl<'a> Help<'a> { }); match &tag_buf.get_ref()[0..tag_length] { b"?" => { - self.writer.write(b"Could not decode tag name")?; + try!(self.writer.write(b"Could not decode tag name")); } b"bin" => { - self.write_bin_name(parser)?; + try!(self.write_bin_name(&parser)); } b"version" => { - write!(self.writer, - "{}", - parser.meta.version.unwrap_or("unknown version"))?; + try!(write!(self.writer, + "{}", + parser.meta.version.unwrap_or("unknown version"))); } b"author" => { - write!(self.writer, - "{}", - parser.meta.author.unwrap_or("unknown author"))?; + try!(write!(self.writer, + "{}", + parser.meta.author.unwrap_or("unknown author"))); } b"about" => { - write!(self.writer, - "{}", - parser.meta.about.unwrap_or("unknown about"))?; + try!(write!(self.writer, + "{}", + parser.meta.about.unwrap_or("unknown about"))); } b"usage" => { - write!(self.writer, "{}", parser.create_usage_no_title(&[]))?; + try!(write!(self.writer, "{}", parser.create_usage_no_title(&[]))); } b"all-args" => { - self.write_all_args(parser)?; + try!(self.write_all_args(&parser)); } b"unified" => { let opts_flags = parser.flags() .map(as_arg_trait) .chain(parser.opts().map(as_arg_trait)); - self.write_args(opts_flags)?; + try!(self.write_args(opts_flags)); } b"flags" => { - self.write_args(parser.flags().map(as_arg_trait))?; + try!(self.write_args(parser.flags() + .map(as_arg_trait))); } b"options" => { - self.write_args(parser.opts().map(as_arg_trait))?; + try!(self.write_args(parser.opts() + .map(as_arg_trait))); } b"positionals" => { - self.write_args(parser.positionals().map(as_arg_trait))?; + try!(self.write_args(parser.positionals() + .map(as_arg_trait))); } b"subcommands" => { - self.write_subcommands(parser)?; + try!(self.write_subcommands(&parser)); } b"after-help" => { - write!(self.writer, - "{}", - parser.meta.more_help.unwrap_or("unknown after-help"))?; + try!(write!(self.writer, + "{}", + parser.meta.more_help.unwrap_or("unknown after-help"))); } b"before-help" => { - write!(self.writer, - "{}", - parser.meta.pre_help.unwrap_or("unknown before-help"))?; + try!(write!(self.writer, + "{}", + parser.meta.pre_help.unwrap_or("unknown before-help"))); } // Unknown tag, write it back. r => { - self.writer.write(b"{")?; - self.writer.write(r)?; - self.writer.write(b"}")?; + try!(self.writer.write(b"{")); + try!(self.writer.write(r)); + try!(self.writer.write(b"}")); } } } diff --git a/src/app/parser.rs b/src/app/parser.rs index c46d1106..60fa4b49 100644 --- a/src/app/parser.rs +++ b/src/app/parser.rs @@ -740,7 +740,7 @@ impl<'a, 'b> Parser<'a, 'b> if let Some(arg) = needs_val_of { // get the OptBuilder so we can check the settings if let Some(opt) = self.get_opt(arg) { - needs_val_of = self.add_val_to_arg(&*opt, &arg_os, matcher)?; + needs_val_of = try!(self.add_val_to_arg(&*opt, &arg_os, matcher)); // get the next value from the iterator continue; } @@ -754,7 +754,7 @@ impl<'a, 'b> Parser<'a, 'b> continue; } - needs_val_of = self.parse_long_arg(matcher, &arg_os)?; + needs_val_of = try!(self.parse_long_arg(matcher, &arg_os)); if !(needs_val_of.is_none() && self.is_set(AppSettings::AllowLeadingHyphen)) { continue; } @@ -762,7 +762,7 @@ impl<'a, 'b> Parser<'a, 'b> // Try to parse short args like normal, if AllowLeadingHyphen or // AllowNegativeNumbers is set, parse_short_arg will *not* throw // an error, and instead return Ok(None) - needs_val_of = self.parse_short_arg(matcher, &arg_os)?; + needs_val_of = try!(self.parse_short_arg(matcher, &arg_os)); // If it's None, we then check if one of those two AppSettings was set debugln!("AllowLeadingHyphen set...{:?}", self.is_set(AppSettings::AllowLeadingHyphen)); debugln!("AllowNegativeNumbers set...{:?}", self.is_set(AppSettings::AllowNegativeNumbers)); @@ -787,7 +787,7 @@ impl<'a, 'b> Parser<'a, 'b> if pos_sc { if &*arg_os == "help" && self.is_set(AppSettings::NeedsSubcommandHelp) { - self.parse_help_subcommand(it)?; + try!(self.parse_help_subcommand(it)); } subcmd_name = Some(arg_os.to_str().expect(INVALID_UTF8).to_owned()); break; @@ -885,7 +885,7 @@ impl<'a, 'b> Parser<'a, 'b> .any(|&(n, _)| n == &*a)) }) { sdebugln!("Yes"); - self.validate_required(matcher)?; + try!(self.validate_required(matcher)); reqs_validated = true; let should_err = if let Some(v) = matcher.0.args.get(&*o.name) { v.vals.is_empty() && !(o.min_vals.is_some() && o.min_vals.unwrap() == 0) @@ -909,14 +909,14 @@ impl<'a, 'b> Parser<'a, 'b> } } - self.add_defaults(matcher)?; - self.validate_blacklist(matcher)?; - self.validate_num_args(matcher)?; + try!(self.add_defaults(matcher)); + try!(self.validate_blacklist(matcher)); + try!(self.validate_num_args(matcher)); matcher.usage(self.create_usage(&[])); if !(self.settings.is_set(AppSettings::SubcommandsNegateReqs) && subcmd_name.is_some()) && !reqs_validated { - self.validate_required(matcher)?; + try!(self.validate_required(matcher)); } if let Some(pos_sc_name) = subcmd_name { // is this is a real subcommand, or an alias @@ -940,7 +940,7 @@ impl<'a, 'b> Parser<'a, 'b> .next() .expect(INTERNAL_ERROR_MSG) }; - self.parse_subcommand(sc_name, matcher, it)?; + try!(self.parse_subcommand(sc_name, matcher, it)); } else if self.is_set(AppSettings::SubcommandRequired) { let bn = self.meta.bin_name.as_ref().unwrap_or(&self.meta.name); return Err(Error::missing_subcommand(bn, @@ -948,7 +948,7 @@ impl<'a, 'b> Parser<'a, 'b> self.color())); } else if self.is_set(AppSettings::SubcommandRequiredElseHelp) { let mut out = vec![]; - self.write_help_err(&mut out)?; + try!(self.write_help_err(&mut out)); return Err(Error { message: String::from_utf8_lossy(&*out).into_owned(), kind: ErrorKind::MissingArgumentOrSubcommand, @@ -958,7 +958,7 @@ impl<'a, 'b> Parser<'a, 'b> if matcher.is_empty() && matcher.subcommand_name().is_none() && self.is_set(AppSettings::ArgRequiredElseHelp) { let mut out = vec![]; - self.write_help_err(&mut out)?; + try!(self.write_help_err(&mut out)); return Err(Error { message: String::from_utf8_lossy(&*out).into_owned(), kind: ErrorKind::MissingArgumentOrSubcommand, @@ -1051,7 +1051,7 @@ impl<'a, 'b> Parser<'a, 'b> "" }, &*sc.p.meta.name)); - sc.p.get_matches_with(&mut sc_matcher, it)?; + try!(sc.p.get_matches_with(&mut sc_matcher, it)); matcher.subcommand(SubCommand { name: sc.p.meta.name.clone(), matches: sc_matcher.into(), @@ -1205,11 +1205,11 @@ impl<'a, 'b> Parser<'a, 'b> arg.to_str().unwrap()); if arg == "help" && self.settings.is_set(AppSettings::NeedsLongHelp) { sdebugln!("Help"); - self._help()?; + try!(self._help()); } if arg == "version" && self.settings.is_set(AppSettings::NeedsLongVersion) { sdebugln!("Version"); - self._version()?; + try!(self._version()); } sdebugln!("Neither"); @@ -1221,13 +1221,13 @@ impl<'a, 'b> Parser<'a, 'b> if let Some(h) = self.help_short { if arg == h && self.settings.is_set(AppSettings::NeedsLongHelp) { sdebugln!("Help"); - self._help()?; + try!(self._help()); } } if let Some(v) = self.version_short { if arg == v && self.settings.is_set(AppSettings::NeedsLongVersion) { sdebugln!("Version"); - self._version()?; + try!(self._version()); } } sdebugln!("Neither"); @@ -1236,7 +1236,7 @@ impl<'a, 'b> Parser<'a, 'b> fn _help(&self) -> ClapResult<()> { let mut buf = vec![]; - Help::write_parser_help(&mut buf, self)?; + try!(Help::write_parser_help(&mut buf, self)); Err(Error { message: unsafe { String::from_utf8_unchecked(buf) }, kind: ErrorKind::HelpDisplayed, @@ -1247,7 +1247,7 @@ impl<'a, 'b> Parser<'a, 'b> fn _version(&self) -> ClapResult<()> { let out = io::stdout(); let mut buf_w = BufWriter::new(out.lock()); - self.print_version(&mut buf_w)?; + try!(self.print_version(&mut buf_w)); Err(Error { message: String::new(), kind: ErrorKind::VersionDisplayed, @@ -1285,7 +1285,7 @@ impl<'a, 'b> Parser<'a, 'b> .any(|&(n, _)| n == &*arg)) }) { debugln!("Found valid opt '{}'", opt.to_string()); - let ret = self.parse_opt(val, opt, matcher)?; + let ret = try!(self.parse_opt(val, opt, matcher)); arg_post_processing!(self, opt, matcher); return Ok(ret); @@ -1303,9 +1303,9 @@ impl<'a, 'b> Parser<'a, 'b> debugln!("Found valid flag '{}'", flag.to_string()); // Only flags could be help or version, and we need to check the raw long // so this is the first point to check - self.check_for_help_and_version_str(arg)?; + try!(self.check_for_help_and_version_str(arg)); - self.parse_flag(flag, matcher)?; + try!(self.parse_flag(flag, matcher)); // Handle conflicts, requirements, etc. arg_post_processing!(self, flag, matcher); @@ -1359,7 +1359,7 @@ impl<'a, 'b> Parser<'a, 'b> }; // Default to "we're expecting a value later" - let ret = self.parse_opt(val, opt, matcher)?; + let ret = try!(self.parse_opt(val, opt, matcher)); arg_post_processing!(self, opt, matcher); @@ -1369,8 +1369,8 @@ impl<'a, 'b> Parser<'a, 'b> .find(|&v| v.short.is_some() && v.short.unwrap() == c) { debugln!("Found valid short flag -{}", c); // Only flags can be help or version - self.check_for_help_and_version_char(c)?; - self.parse_flag(flag, matcher)?; + try!(self.check_for_help_and_version_char(c)); + try!(self.parse_flag(flag, matcher)); // Handle conflicts, requirements, overrides, etc. // Must be called here due to mutablilty arg_post_processing!(self, flag, matcher); @@ -1409,7 +1409,7 @@ impl<'a, 'b> Parser<'a, 'b> } sdebugln!("Found - {:?}, len: {}", v, v.len_()); debugln!("{:?} contains '='...{:?}", fv, fv.starts_with(&[b'='])); - self.add_val_to_arg(opt, v, matcher)?; + try!(self.add_val_to_arg(opt, v, matcher)); } else { sdebugln!("None"); } @@ -1439,10 +1439,10 @@ impl<'a, 'b> Parser<'a, 'b> if !(self.trailing_vals && self.is_set(AppSettings::DontDelimitTrailingValues)) { if let Some(delim) = arg.val_delim() { if val.is_empty_() { - ret = self.add_single_val_to_arg(arg, val, matcher)?; + ret = try!(self.add_single_val_to_arg(arg, val, matcher)); } else { for v in val.split(delim as u32 as u8) { - ret = self.add_single_val_to_arg(arg, v, matcher)?; + ret = try!(self.add_single_val_to_arg(arg, v, matcher)); } // If there was a delimiter used, we're not looking for more values if val.contains_byte(delim as u32 as u8) || @@ -1451,10 +1451,10 @@ impl<'a, 'b> Parser<'a, 'b> } } } else { - ret = self.add_single_val_to_arg(arg, val, matcher)?; + ret = try!(self.add_single_val_to_arg(arg, val, matcher)); } } else { - ret = self.add_single_val_to_arg(arg, val, matcher)?; + ret = try!(self.add_single_val_to_arg(arg, val, matcher)); } Ok(ret) } @@ -1605,11 +1605,11 @@ impl<'a, 'b> Parser<'a, 'b> } else if let Some(opt) = self.opts .iter() .find(|o| &o.name == name) { - self._validate_num_vals(opt, ma, matcher)?; + try!(self._validate_num_vals(opt, ma, matcher)); } else if let Some(pos) = self.positionals .values() .find(|p| &p.name == name) { - self._validate_num_vals(pos, ma, matcher)?; + try!(self._validate_num_vals(pos, ma, matcher)); } } Ok(()) @@ -1894,7 +1894,7 @@ impl<'a, 'b> Parser<'a, 'b> // Prints the version to the user and exits if quit=true fn print_version(&self, w: &mut W) -> ClapResult<()> { - self.write_version(w)?; + try!(self.write_version(w)); w.flush().map_err(Error::from) } @@ -1938,9 +1938,9 @@ impl<'a, 'b> Parser<'a, 'b> macro_rules! add_val { ($_self:ident, $a:ident, $m:ident) => { if $m.get($a.name).is_none() { - $_self.add_val_to_arg($a, OsStr::new($a.default_val + try!($_self.add_val_to_arg($a, OsStr::new($a.default_val .as_ref() - .unwrap()), $m)?; + .unwrap()), $m)); arg_post_processing!($_self, $a, $m); } }; diff --git a/src/app/settings.rs b/src/app/settings.rs index b8d86c1f..fa43fa73 100644 --- a/src/app/settings.rs +++ b/src/app/settings.rs @@ -363,7 +363,7 @@ pub enum AppSettings { /// ``` /// [`SubCommand`]: ./struct.SubCommand.html DisableVersion, - + /// Displays the arguments and [`SubCommand`]s in the help message in the order that they were /// declared in, and not alphabetically which is the default. /// @@ -667,6 +667,7 @@ pub enum AppSettings { #[doc(hidden)] LowIndexMultiplePositional, + } impl FromStr for AppSettings { diff --git a/src/args/any_arg.rs b/src/args/any_arg.rs index 1fa8f215..09408230 100644 --- a/src/args/any_arg.rs +++ b/src/args/any_arg.rs @@ -1,6 +1,6 @@ // Std use std::rc::Rc; -use std::fmt as std_fmt; +use std::fmt as std_fmt; // Third Party use vec_map::VecMap; diff --git a/src/args/arg_builder/flag.rs b/src/args/arg_builder/flag.rs index 756cbc9d..2f5c648b 100644 --- a/src/args/arg_builder/flag.rs +++ b/src/args/arg_builder/flag.rs @@ -87,9 +87,9 @@ impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>> for FlagBuilder<'a, 'b> { impl<'n, 'e> Display for FlagBuilder<'n, 'e> { fn fmt(&self, f: &mut Formatter) -> Result { if let Some(l) = self.long { - write!(f, "--{}", l)?; + try!(write!(f, "--{}", l)); } else { - write!(f, "-{}", self.short.unwrap())?; + try!(write!(f, "-{}", self.short.unwrap())); } Ok(()) @@ -180,9 +180,10 @@ impl<'n, 'e> AnyArg<'n, 'e> for FlagBuilder<'n, 'e> { } fn aliases(&self) -> Option> { if let Some(ref aliases) = self.aliases { - let vis_aliases: Vec<_> = aliases.iter() - .filter_map(|&(n, v)| if v { Some(n) } else { None }) - .collect(); + let vis_aliases: Vec<_> = + aliases.iter() + .filter_map(|&(n, v)| if v { Some(n) } else { None }) + .collect(); if vis_aliases.is_empty() { None } else { @@ -232,8 +233,12 @@ mod test { fn flagbuilder_display_multiple_aliases() { let mut f = FlagBuilder::new("flg"); f.short = Some('f'); - f.aliases = - Some(vec![("alias_not_visible", false), ("f2", true), ("f3", true), ("f4", true)]); + f.aliases = Some(vec![ + ("alias_not_visible", false), + ("f2", true), + ("f3", true), + ("f4", true) + ]); assert_eq!(&*format!("{}", f), "-f"); } } diff --git a/src/args/arg_builder/option.rs b/src/args/arg_builder/option.rs index d2e2134d..1452172f 100644 --- a/src/args/arg_builder/option.rs +++ b/src/args/arg_builder/option.rs @@ -125,41 +125,41 @@ impl<'n, 'e> Display for OptBuilder<'n, 'e> { debugln!("fn=fmt"); // Write the name such --long or -l if let Some(l) = self.long { - write!(f, "--{} ", l)?; + try!(write!(f, "--{} ", l)); } else { - write!(f, "-{} ", self.short.unwrap())?; + try!(write!(f, "-{} ", self.short.unwrap())); } // Write the values such as if let Some(ref vec) = self.val_names { let mut it = vec.iter().peekable(); while let Some((_, val)) = it.next() { - write!(f, "<{}>", val)?; + try!(write!(f, "<{}>", val)); if it.peek().is_some() { - write!(f, " ")?; + try!(write!(f, " ")); } } let num = vec.len(); if self.is_set(ArgSettings::Multiple) && num == 1 { - write!(f, "...")?; + try!(write!(f, "...")); } } else if let Some(num) = self.num_vals { let mut it = (0..num).peekable(); while let Some(_) = it.next() { - write!(f, "<{}>", self.name)?; + try!(write!(f, "<{}>", self.name)); if it.peek().is_some() { - write!(f, " ")?; + try!(write!(f, " ")); } } } else { - write!(f, - "<{}>{}", - self.name, - if self.is_set(ArgSettings::Multiple) { - "..." - } else { - "" - })?; + try!(write!(f, + "<{}>{}", + self.name, + if self.is_set(ArgSettings::Multiple) { + "..." + } else { + "" + })); } Ok(()) @@ -259,9 +259,10 @@ impl<'n, 'e> AnyArg<'n, 'e> for OptBuilder<'n, 'e> { } fn aliases(&self) -> Option> { if let Some(ref aliases) = self.aliases { - let vis_aliases: Vec<_> = aliases.iter() - .filter_map(|&(n, v)| if v { Some(n) } else { None }) - .collect(); + let vis_aliases: Vec<_> = + aliases.iter() + .filter_map(|&(n, v)| if v { Some(n) } else { None }) + .collect(); if vis_aliases.is_empty() { None } else { @@ -334,8 +335,12 @@ mod test { fn optbuilder_display_multiple_aliases() { let mut o = OptBuilder::new("opt"); o.long = Some("option"); - o.aliases = - Some(vec![("als_not_visible", false), ("als2", true), ("als3", true), ("als4", true)]); + o.aliases = Some(vec![ + ("als_not_visible", false), + ("als2", true), + ("als3", true), + ("als4", true) + ]); assert_eq!(&*format!("{}", o), "--option "); } } diff --git a/src/args/arg_builder/positional.rs b/src/args/arg_builder/positional.rs index 7de6b2f1..ec8c66f0 100644 --- a/src/args/arg_builder/positional.rs +++ b/src/args/arg_builder/positional.rs @@ -136,17 +136,17 @@ impl<'n, 'e> PosBuilder<'n, 'e> { impl<'n, 'e> Display for PosBuilder<'n, 'e> { fn fmt(&self, f: &mut Formatter) -> Result { if let Some(ref names) = self.val_names { - write!(f, - "{}", - names.values() - .map(|n| format!("<{}>", n)) - .collect::>() - .join(" "))?; + try!(write!(f, + "{}", + names.values() + .map(|n| format!("<{}>", n)) + .collect::>() + .join(" "))); } else { - write!(f, "<{}>", self.name)?; + try!(write!(f, "<{}>", self.name)); } if self.settings.is_set(ArgSettings::Multiple) && self.val_names.is_none() { - write!(f, "...")?; + try!(write!(f, "...")); } Ok(()) diff --git a/src/completions/bash.rs b/src/completions/bash.rs index 5324a772..2db27355 100644 --- a/src/completions/bash.rs +++ b/src/completions/bash.rs @@ -19,7 +19,7 @@ impl<'a, 'b> BashGen<'a, 'b> { pub fn generate_to(&self, buf: &mut W) { - w!(buf, + w!(buf, format!("_{name}() {{ local i cur prev opts cmds COMPREPLY=() @@ -177,9 +177,9 @@ complete -F _{name} {name} let mut it = vec.iter().peekable(); while let Some((_, val)) = it.next() { ret = format!("{}<{}>{}", - ret, - val, - if it.peek().is_some() { " " } else { "" }); + ret, + val, + if it.peek().is_some() { " " } else { "" }); } let num = vec.len(); if o.is_set(ArgSettings::Multiple) && num == 1 { @@ -189,9 +189,9 @@ complete -F _{name} {name} let mut it = (0..num).peekable(); while let Some(_) = it.next() { ret = format!("{}<{}>{}", - ret, - o.name(), - if it.peek().is_some() { " " } else { "" }); + ret, + o.name(), + if it.peek().is_some() { " " } else { "" }); } if o.is_set(ArgSettings::Multiple) && num == 1 { ret = format!("{}...", ret); diff --git a/src/completions/fish.rs b/src/completions/fish.rs index e399b8db..a83e2e96 100644 --- a/src/completions/fish.rs +++ b/src/completions/fish.rs @@ -20,7 +20,8 @@ impl<'a, 'b> FishGen<'a, 'b> { let command = self.p.meta.bin_name.as_ref().unwrap(); // function to detect subcommand - let detect_subcommand_function = r#"function __fish_using_command + let detect_subcommand_function = +r#"function __fish_using_command set cmd (commandline -opc) if [ (count $cmd) -eq (count $argv) ] for i in (seq (count $argv)) @@ -33,8 +34,7 @@ impl<'a, 'b> FishGen<'a, 'b> { return 1 end -"# - .to_string(); +"#.to_string(); let mut buffer = detect_subcommand_function; gen_fish_inner(command, self, &command.to_string(), &mut buffer); @@ -42,7 +42,10 @@ end } } -fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, parent_cmds: &str, buffer: &mut String) { +fn gen_fish_inner(root_command: &str, + comp_gen: &FishGen, + parent_cmds: &str, + buffer: &mut String) { // example : // // complete @@ -56,8 +59,8 @@ fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, parent_cmds: &str, buf // -n "__fish_using_command myprog subcmd1" # complete for command "myprog subcmd1" let basic_template = format!("complete -c {} -n \"__fish_using_command {}\"", - root_command, - parent_cmds); + root_command, + parent_cmds); for option in &comp_gen.p.opts { let mut template = basic_template.clone(); @@ -109,6 +112,9 @@ fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, parent_cmds: &str, buf sub_parent_cmds.push_str(" "); } sub_parent_cmds.push_str(&subcommand.p.meta.name); - gen_fish_inner(root_command, &sub_comp_gen, &sub_parent_cmds, buffer); + gen_fish_inner(root_command, + &sub_comp_gen, + &sub_parent_cmds, + buffer); } } \ No newline at end of file diff --git a/src/completions/mod.rs b/src/completions/mod.rs index 753ec72c..0c33bdb6 100644 --- a/src/completions/mod.rs +++ b/src/completions/mod.rs @@ -30,16 +30,16 @@ impl<'a, 'b> ComplGen<'a, 'b> { pub fn generate(&self, for_shell: Shell, buf: &mut W) { match for_shell { - Shell::Bash => BashGen::new(self.p).generate_to(buf), - Shell::Fish => FishGen::new(self.p).generate_to(buf), - Shell::Zsh => ZshGen::new(self.p).generate_to(buf), + Shell::Bash => BashGen::new(self.p).generate_to(buf), + Shell::Fish => FishGen::new(self.p).generate_to(buf), + Shell::Zsh => ZshGen::new(self.p).generate_to(buf), Shell::PowerShell => PowerShellGen::new(self.p).generate_to(buf), } } } // Gets all subcommands including child subcommands in the form of 'name' where the name -// is a single word (i.e. "install") of the path to said subcommand (i.e. +// is a single word (i.e. "install") of the path to said subcommand (i.e. // "rustup toolchain install") // // Also note, aliases are treated as their own subcommands but duplicates of whatever they're @@ -55,7 +55,7 @@ pub fn all_subcommand_names(p: &Parser) -> Vec { } // Gets all subcommands including child subcommands in the form of ('name', 'bin_name') where the name -// is a single word (i.e. "install") of the path and full bin_name of said subcommand (i.e. +// is a single word (i.e. "install") of the path and full bin_name of said subcommand (i.e. // "rustup toolchain install") // // Also note, aliases are treated as their own subcommands but duplicates of whatever they're @@ -75,9 +75,7 @@ pub fn all_subcommands(p: &Parser) -> Vec<(String, String)> { // Also note, aliases are treated as their own subcommands but duplicates of whatever they're // aliasing. pub fn subcommands_of(p: &Parser) -> Vec<(String, String)> { - debugln!("fn=subcommands_of;name={};bin_name={}", - p.meta.name, - p.meta.bin_name.as_ref().unwrap()); + debugln!("fn=subcommands_of;name={};bin_name={}", p.meta.name, p.meta.bin_name.as_ref().unwrap()); let mut subcmds = vec![]; debug!("Has subcommands..."); @@ -88,8 +86,7 @@ pub fn subcommands_of(p: &Parser) -> Vec<(String, String)> { if let Some(ref aliases) = p.meta.aliases { for &(n, _) in aliases { debugln!("Found alias...{}", n); - let mut als_bin_name: Vec<_> = - p.meta.bin_name.as_ref().unwrap().split(' ').collect(); + let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(' ').collect(); als_bin_name.push(n); let old = als_bin_name.len() - 2; als_bin_name.swap_remove(old); @@ -97,19 +94,16 @@ pub fn subcommands_of(p: &Parser) -> Vec<(String, String)> { } } return ret; - } + } sdebugln!("Yes"); for sc in &p.subcommands { - debugln!("iter;name={};bin_name={}", - sc.p.meta.name, - sc.p.meta.bin_name.as_ref().unwrap()); + debugln!("iter;name={};bin_name={}", sc.p.meta.name, sc.p.meta.bin_name.as_ref().unwrap()); debugln!("Looking for aliases..."); if let Some(ref aliases) = sc.p.meta.aliases { for &(n, _) in aliases { debugln!("Found alias...{}", n); - let mut als_bin_name: Vec<_> = - p.meta.bin_name.as_ref().unwrap().split(' ').collect(); + let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(' ').collect(); als_bin_name.push(n); let old = als_bin_name.len() - 2; als_bin_name.swap_remove(old); diff --git a/src/completions/powershell.rs b/src/completions/powershell.rs index 2d921e63..928b8c55 100644 --- a/src/completions/powershell.rs +++ b/src/completions/powershell.rs @@ -32,9 +32,7 @@ impl<'a, 'b> PowerShellGen<'a, 'b> { bin_names.push(format!(r"./{0}.exe", bin_name)); } - let bin_names = bin_names.iter().fold(String::new(), |previous, current| { - format!("{0}, '{1}'", previous, current) - }); + let bin_names = bin_names.iter().fold(String::new(), |previous, current| format!("{0}, '{1}'", previous, current)); let bin_names = bin_names.trim_left_matches(", "); let result = format!(r#" @@ -77,17 +75,18 @@ impl<'a, 'b> PowerShellGen<'a, 'b> { fn generate_inner<'a, 'b>(p: &Parser<'a, 'b>, previous_command_name: &str) -> (String, String) { let command_name = format!("{}_{}", previous_command_name, &p.meta.name); - let mut subcommands_detection_cases = if previous_command_name == "" { - String::new() - } else { - format!(r" + let mut subcommands_detection_cases = + if previous_command_name == "" { + String::new() + } + else { + format!(r" '{0}' {{ $command += '_{0}' break }} -", - &p.meta.name) - }; +", &p.meta.name) + }; let mut completions = String::new(); for subcommand in &p.subcommands { @@ -104,13 +103,10 @@ fn generate_inner<'a, 'b>(p: &Parser<'a, 'b>, previous_command_name: &str) -> (S '{}' {{ $completions = @({}) }} -", - &command_name, - completions.trim_right_matches(", ")); +", &command_name, completions.trim_right_matches(", ")); for subcommand in &p.subcommands { - let (subcommand_subcommands_detection_cases, subcommand_subcommands_cases) = - generate_inner(&subcommand.p, &command_name); + let (subcommand_subcommands_detection_cases, subcommand_subcommands_cases) = generate_inner(&subcommand.p, &command_name); subcommands_detection_cases.push_str(&subcommand_subcommands_detection_cases); subcommands_cases.push_str(&subcommand_subcommands_cases); } diff --git a/src/completions/shell.rs b/src/completions/shell.rs index f57328b4..d8810f7e 100644 --- a/src/completions/shell.rs +++ b/src/completions/shell.rs @@ -19,7 +19,12 @@ pub enum Shell { impl Shell { /// A list of possible variants in `&'static str` form pub fn variants() -> [&'static str; 4] { - ["zsh", "bash", "fish", "powershell"] + [ + "zsh", + "bash", + "fish", + "powershell" + ] } } @@ -33,7 +38,9 @@ impl FromStr for Shell { "FISH" | _ if s.eq_ignore_ascii_case("fish") => Ok(Shell::Fish), "BASH" | _ if s.eq_ignore_ascii_case("bash") => Ok(Shell::Bash), "POWERSHELL" | _ if s.eq_ignore_ascii_case("powershell") => Ok(Shell::PowerShell), - _ => Err(String::from("[valid values: bash, fish, zsh, powershell]")), + _ => Err( + String::from("[valid values: bash, fish, zsh, powershell]") + ), } } } @@ -41,10 +48,11 @@ impl FromStr for Shell { impl fmt::Display for Shell { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Shell::Bash => write!(f, "BASH"), - Shell::Fish => write!(f, "FISH"), - Shell::Zsh => write!(f, "ZSH"), + Shell::Bash => write!(f, "BASH"), + Shell::Fish => write!(f, "FISH"), + Shell::Zsh => write!(f, "ZSH"), Shell::PowerShell => write!(f, "POWERSHELL"), } } } + diff --git a/src/completions/zsh.rs b/src/completions/zsh.rs index 7b10d5a9..576f1ce1 100644 --- a/src/completions/zsh.rs +++ b/src/completions/zsh.rs @@ -19,13 +19,15 @@ pub struct ZshGen<'a, 'b> impl<'a, 'b> ZshGen<'a, 'b> { pub fn new(p: &'b Parser<'a, 'b>) -> Self { debugln!("fn=ZshGen::new;"); - ZshGen { p: p } + ZshGen { + p: p, + } } pub fn generate_to(&self, buf: &mut W) { debugln!("fn=generate_to;"); w!(buf, - format!("\ + format!("\ #compdef {name} _{name}() {{ @@ -43,8 +45,7 @@ _{name} \"$@\"", name = self.p.meta.bin_name.as_ref().unwrap(), initial_args = get_args_of(self.p), subcommands = get_subcommands_of(self.p), - subcommand_details = subcommand_details(self.p)) - .as_bytes()); + subcommand_details = subcommand_details(self.p)).as_bytes()); } } @@ -71,11 +72,11 @@ _{name} \"$@\"", // local commands; commands=( // 'show:Show the active and installed toolchains' // 'update:Update Rust toolchains' -// # ... snip for brevity +// # ... snip for brevity // 'help:Prints this message or the help of the given subcommand(s)' // ) // _describe -t commands 'rustup commands' commands "$@" -// +// fn subcommand_details(p: &Parser) -> String { debugln!("fn=subcommand_details"); // First we do ourself @@ -87,10 +88,9 @@ _{bin_name_underscore}_commands() {{ ) _describe -t commands '{bin_name} commands' commands \"$@\" }}", - bin_name_underscore = - p.meta.bin_name.as_ref().unwrap().replace(" ", "_"), - bin_name = p.meta.bin_name.as_ref().unwrap(), - subcommands_and_args = subcommands_and_args_of(p))]; + bin_name_underscore = p.meta.bin_name.as_ref().unwrap().replace(" ", "_"), + bin_name = p.meta.bin_name.as_ref().unwrap(), + subcommands_and_args = subcommands_and_args_of(p))]; // Next we start looping through all the children, grandchildren, etc. let mut all_subcommands = completions::all_subcommands(p); @@ -106,15 +106,15 @@ _{bin_name_underscore}_commands() {{ ) _describe -t commands '{bin_name} commands' commands \"$@\" }}", - bin_name_underscore = bin_name.replace(" ", "_"), - bin_name = bin_name, - subcommands_and_args = subcommands_and_args_of(parser_of(p, bin_name)))); + bin_name_underscore = bin_name.replace(" ", "_"), + bin_name = bin_name, + subcommands_and_args = subcommands_and_args_of(parser_of(p, bin_name)))); } ret.join("\n") } -// Generates subcommand and positional argument completions in form of +// Generates subcommand and positional argument completions in form of // // '[arg_name]:[arg_help]' // @@ -129,9 +129,9 @@ fn subcommands_and_args_of(p: &Parser) -> String { debugln!("fn=subcommands_and_args_of;"); let mut ret = vec![]; fn add_sc(sc: &App, n: &str, ret: &mut Vec) { - let s = format!("\"{name}:{help}\" \\", - name = n, - help = sc.p.meta.about.unwrap_or("")); + let s = format!("\"{name}:{help}\" \\", + name = n, + help = sc.p.meta.about.unwrap_or("")); if !s.is_empty() { ret.push(s); } @@ -142,7 +142,7 @@ fn subcommands_and_args_of(p: &Parser) -> String { debugln!("iter;subcommand={}", sc.p.meta.name); add_sc(sc, &sc.p.meta.name, &mut ret); if let Some(ref v) = sc.p.meta.aliases { - for alias in v.iter().filter(|&&(_, vis)| vis).map(|&(n, _)| n) { + for alias in v.iter().filter(|&&(_, vis)| vis).map(|&(n,_)| n) { add_sc(sc, alias, &mut ret); } } @@ -151,10 +151,10 @@ fn subcommands_and_args_of(p: &Parser) -> String { // Then the positional args for arg in p.positionals() { debugln!("iter;arg={}", arg.name); - let a = format!("\"{name}:{help}\" \\", - name = arg.name.to_ascii_uppercase(), - help = arg.help.unwrap_or("")); - + let a = format!("\"{name}:{help}\" \\", + name = arg.name.to_ascii_uppercase(), + help = arg.help.unwrap_or("")); + if !a.is_empty() { ret.push(a); } @@ -184,7 +184,7 @@ fn subcommands_and_args_of(p: &Parser) -> String { // // esac // ;; -// esac", +// esac", // // Where the following variables are present: // [name] = The subcommand name in the form of "install" for "rustup toolchain install" @@ -220,17 +220,18 @@ fn get_subcommands_of(p: &Parser) -> String { subcmds.push(v.join("\n")); } - format!("case $state in + format!( +"case $state in ({name}) curcontext=\"${{curcontext%:*:*}}:{name_hyphen}-command-$words[1]:\" case $line[1] in {subcommands} esac ;; -esac", - name = p.meta.name, - name_hyphen = p.meta.bin_name.as_ref().unwrap().replace(" ", "-"), - subcommands = subcmds.join("\n")) +esac", + name = p.meta.name, + name_hyphen = p.meta.bin_name.as_ref().unwrap().replace(" ", "-"), + subcommands = subcmds.join("\n")) } fn parser_of<'a, 'b>(p: &'b Parser<'a, 'b>, sc: &str) -> &'b Parser<'a, 'b> { @@ -238,7 +239,7 @@ fn parser_of<'a, 'b>(p: &'b Parser<'a, 'b>, sc: &str) -> &'b Parser<'a, 'b> { &p.find_subcommand(sc).expect(INTERNAL_ERROR_MSG).p } -// Writes out the args section, which ends up being the flags and opts, and a jump to +// Writes out the args section, which ends up being the flags and opts, and a jump to // another ZSH function if there are positional args or subcommands. // The structer works like this: // ([conflicting_args]) [multiple] arg [takes_value] [[help]] [: :(possible_values)] @@ -264,15 +265,15 @@ fn get_args_of(p: &Parser) -> String { let opts = write_opts_of(p); let flags = write_flags_of(p); let sc_or_a = if p.has_subcommands() || p.has_positionals() { - format!("\"1:: :_{name}_commands\" \\", + format!("\"1:: :_{name}_commands\" \\", name = p.meta.bin_name.as_ref().unwrap().replace(" ", "_")) - } else { - String::new() - }; - let sc = if p.has_subcommands() { - format!("\"*:: :->{name}\" \\", name = p.meta.name) - } else { - String::new() + } else { + String::new() + }; + let sc = if p.has_subcommands() { + format!("\"*:: :->{name}\" \\", name = p.meta.name) + } else { + String::new() }; if !opts.is_empty() { @@ -298,41 +299,33 @@ fn write_opts_of(p: &Parser) -> String { for o in p.opts() { debugln!("iter;o={}", o.name()); let help = o.help().unwrap_or(""); - let mut conflicts = get_zsh_arg_conflicts!(p, o, INTERNAL_ERROR_MSG); - conflicts = if conflicts.is_empty() { - String::new() - } else { - format!("({})", conflicts) - }; + let mut conflicts = get_zsh_arg_conflicts!(p, o, INTERNAL_ERROR_MSG); + conflicts = if conflicts.is_empty() { String::new() } else { format!("({})", conflicts) }; - let multiple = if o.is_set(ArgSettings::Multiple) { - "*" - } else { - "" - }; + let multiple = if o.is_set(ArgSettings::Multiple) { "*" } else { "" }; let pv = if let Some(pv_vec) = o.possible_vals() { - format!(": :({})", pv_vec.join(" ")) + format!(": :({})", pv_vec.join(" ")) } else { String::new() }; if let Some(short) = o.short() { let s = format!("\"{conflicts}{multiple}-{arg}+[{help}]{possible_values}\" \\", - conflicts = conflicts, - multiple = multiple, - arg = short, - possible_values = pv, - help = help); + conflicts = conflicts, + multiple = multiple, + arg = short, + possible_values = pv, + help = help); debugln!("Wrote...{}", &*s); ret.push(s); } if let Some(long) = o.long() { let l = format!("\"{conflicts}{multiple}--{arg}+[{help}]{possible_values}\" \\", - conflicts = conflicts, - multiple = multiple, - arg = long, - possible_values = pv, - help = help); + conflicts = conflicts, + multiple = multiple, + arg = long, + possible_values = pv, + help = help); debugln!("Wrote...{}", &*l); ret.push(l); @@ -348,24 +341,16 @@ fn write_flags_of(p: &Parser) -> String { for f in p.flags() { debugln!("iter;f={}", f.name()); let help = f.help().unwrap_or(""); - let mut conflicts = get_zsh_arg_conflicts!(p, f, INTERNAL_ERROR_MSG); - conflicts = if conflicts.is_empty() { - String::new() - } else { - format!("({})", conflicts) - }; + let mut conflicts = get_zsh_arg_conflicts!(p, f, INTERNAL_ERROR_MSG); + conflicts = if conflicts.is_empty() { String::new() } else { format!("({})", conflicts) }; - let multiple = if f.is_set(ArgSettings::Multiple) { - "*" - } else { - "" - }; + let multiple = if f.is_set(ArgSettings::Multiple) { "*" } else { "" }; if let Some(short) = f.short() { let s = format!("\"{conflicts}{multiple}-{arg}[{help}]\" \\", - multiple = multiple, - conflicts = conflicts, - arg = short, - help = help); + multiple = multiple, + conflicts = conflicts, + arg = short, + help = help); debugln!("Wrote...{}", &*s); ret.push(s); @@ -373,10 +358,10 @@ fn write_flags_of(p: &Parser) -> String { if let Some(long) = f.long() { let l = format!("\"{conflicts}{multiple}--{arg}[{help}]\" \\", - conflicts = conflicts, - multiple = multiple, - arg = long, - help = help); + conflicts = conflicts, + multiple = multiple, + arg = long, + help = help); debugln!("Wrote...{}", &*l); ret.push(l); diff --git a/src/errors.rs b/src/errors.rs index 433af2cf..bb732249 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -52,7 +52,7 @@ pub enum ErrorKind { UnknownArgument, /// Occurs when the user provides an unrecognized [`SubCommand`] which meets the threshold for - /// being similar enough to an existing subcommand. + /// being similar enough to an existing subcommand. /// If it doesn't meet the threshold, or the 'suggestions' feature is disabled, /// the more general [`UnknownArgument`] error is returned. /// @@ -77,7 +77,7 @@ pub enum ErrorKind { /// Occurs when the user provides an unrecognized [`SubCommand`] which either /// doesn't meet the threshold for being similar enough to an existing subcommand, - /// or the 'sggestions' feature is disabled. + /// or the 'sggestions' feature is disabled. /// Otherwise the more detailed [`InvalidSubcommand`] error is returned. /// /// This error typically happens when passing additional subcommand names to the `help` diff --git a/src/macros.rs b/src/macros.rs index b6d83131..9478857c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -626,7 +626,7 @@ macro_rules! write_spaces { ($num:expr, $w:ident) => ({ debugln!("macro=write_spaces!;"); for _ in 0..$num { - write!($w, " ")?; + try!(write!($w, " ")); } }) } @@ -639,7 +639,7 @@ macro_rules! write_nspaces { ($dst:expr, $num:expr) => ({ debugln!("macro=write_spaces!;num={}", $num); for _ in 0..$num { - $dst.write(b" ")?; + try!($dst.write(b" ")); } }) } diff --git a/src/usage_parser.rs b/src/usage_parser.rs index 54361bf3..7c6807c8 100644 --- a/src/usage_parser.rs +++ b/src/usage_parser.rs @@ -111,7 +111,7 @@ impl<'a> UsageParser<'a> { { debugln!("fn=stop_at;"); self.start = self.pos; - self.pos += self.usage[self.start..].bytes().take_while(|&b| f(b)).count(); + self.pos += self.usage[self.start..].bytes().take_while(|&b| f(b) ).count(); } fn short_or_long(&mut self, arg: &mut Arg<'a, 'a>) { @@ -990,8 +990,7 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().values().collect::>(), - [&"option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), [&"option"]); assert!(d.num_vals.is_none()); } @@ -1200,8 +1199,7 @@ mod test { let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'"); assert_eq!(a.name, "ñämê"); assert_eq!(a.long, Some("ôpt")); - assert_eq!(a.val_names.unwrap().values().collect::>(), - [&"üñíčöĐ€"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"üñíčöĐ€"]); assert_eq!(a.help, Some("hælp")); } }