mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Merge pull request #1016 from kbknapp/unicode-segmentation-bump
Unicode segmentation bump
This commit is contained in:
commit
1ef6e62e1e
12 changed files with 179 additions and 157 deletions
|
@ -6,7 +6,7 @@ rust:
|
|||
- nightly-2017-01-25
|
||||
- beta
|
||||
- stable
|
||||
- 1.11.0
|
||||
- 1.13.0
|
||||
matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
|
|
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,3 +1,21 @@
|
|||
<a name="v2.26.0"></a>
|
||||
## v2.26.0 (2017-07-29)
|
||||
|
||||
Minimum version of Rust is now v1.13.0 (Stable)
|
||||
|
||||
|
||||
#### Improvements
|
||||
|
||||
* bumps unicode-segmentation to v1.2 ([cd7b40a2](https://github.com/kbknapp/clap-rs/commit/cd7b40a21c77bae17ba453c5512cb82b7d1ce474))
|
||||
|
||||
|
||||
#### Performance
|
||||
|
||||
* update textwrap to version 0.7.0 ([c2d4e637](https://github.com/kbknapp/clap-rs/commit/c2d4e63756a6f070e38c16dff846e9b0a53d6f93))
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="v2.25.1"></a>
|
||||
### v2.25.1 (2017-07-21)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "clap"
|
||||
version = "2.25.1"
|
||||
version = "2.26.0"
|
||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
|
||||
repository = "https://github.com/kbknapp/clap-rs.git"
|
||||
|
@ -23,7 +23,7 @@ appveyor = { repository = "kbknapp/clap-rs" }
|
|||
bitflags = "0.9"
|
||||
vec_map = "0.8"
|
||||
unicode-width = "0.1.4"
|
||||
unicode-segmentation = "~1.1.0" # 1.2.0 requires Rust 1.13.0
|
||||
unicode-segmentation = "1.2.0"
|
||||
textwrap = "0.7.0"
|
||||
strsim = { version = "0.6.0", optional = true }
|
||||
ansi_term = { version = "0.9.0", optional = true }
|
||||
|
|
10
README.md
10
README.md
|
@ -45,12 +45,16 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
|
|||
|
||||
## What's New
|
||||
|
||||
Here's the highlights for v2.25.1
|
||||
Here's the highlights for v2.26.0
|
||||
|
||||
* impl Default for Values + OsValues for any lifetime. ([fb7d6231f1](https://github.com/kbknapp/clap-rs/commit/fb7d6231f13a2f79f411e62dca210b7dc9994c18))
|
||||
* **The minimum required version of Rust is now 1.13.0 (Stable)**
|
||||
* bumps unicode-segmentation to v1.2
|
||||
* update textwrap to version 0.7.0 which increases the performance of writing help strings
|
||||
|
||||
Here's the highlights for v2.21.0 to v2.25.0
|
||||
|
||||
Here's the highlights for v2.21.0 to v2.25.1
|
||||
|
||||
* impl Default for Values + OsValues for any lifetime.
|
||||
* use textwrap crate for wrapping help texts
|
||||
* suggests to use flag after subcommand when applicable
|
||||
* Bumps bitflags crate to v0.9
|
||||
|
|
174
src/app/help.rs
174
src/app/help.rs
|
@ -163,11 +163,11 @@ impl<'a> Help<'a> {
|
|||
pub fn write_help(&mut self, parser: &Parser) -> ClapResult<()> {
|
||||
debugln!("Help::write_help;");
|
||||
if let Some(h) = parser.meta.help_str {
|
||||
try!(write!(self.writer, "{}", h).map_err(Error::from));
|
||||
write!(self.writer, "{}", h).map_err(Error::from)?;
|
||||
} else if let Some(tmpl) = parser.meta.template {
|
||||
try!(self.write_templated_help(parser, tmpl));
|
||||
self.write_templated_help(parser, tmpl)?;
|
||||
} else {
|
||||
try!(self.write_default_help(parser));
|
||||
self.write_default_help(parser)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -197,9 +197,9 @@ impl<'a> Help<'a> {
|
|||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
try!(self.writer.write_all(b"\n"));
|
||||
self.writer.write_all(b"\n")?;
|
||||
}
|
||||
try!(self.write_arg(arg.as_base()));
|
||||
self.write_arg(arg.as_base())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -233,9 +233,9 @@ impl<'a> Help<'a> {
|
|||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
try!(self.writer.write_all(b"\n"));
|
||||
self.writer.write_all(b"\n")?;
|
||||
}
|
||||
try!(self.write_arg(arg.as_base()));
|
||||
self.write_arg(arg.as_base())?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -244,17 +244,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!("Help::write_arg;");
|
||||
try!(self.short(arg));
|
||||
try!(self.long(arg));
|
||||
let spec_vals = try!(self.val(arg));
|
||||
try!(self.help(arg, &*spec_vals));
|
||||
self.short(arg)?;
|
||||
self.long(arg)?;
|
||||
let spec_vals = self.val(arg)?;
|
||||
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!("Help::short;");
|
||||
try!(write!(self.writer, "{}", TAB));
|
||||
write!(self.writer, "{}", TAB)?;
|
||||
if let Some(s) = arg.short() {
|
||||
color!(self, "-{}", s, good)
|
||||
} else if arg.has_switch() {
|
||||
|
@ -273,9 +273,9 @@ impl<'a> Help<'a> {
|
|||
if arg.takes_value() {
|
||||
if let Some(l) = arg.long() {
|
||||
if arg.short().is_some() {
|
||||
try!(write!(self.writer, ", "));
|
||||
write!(self.writer, ", ")?;
|
||||
}
|
||||
try!(color!(self, "--{}", l, good))
|
||||
color!(self, "--{}", l, good)?
|
||||
}
|
||||
|
||||
let sep = if arg.is_set(ArgSettings::RequireEquals) {
|
||||
|
@ -283,12 +283,12 @@ impl<'a> Help<'a> {
|
|||
} else {
|
||||
" "
|
||||
};
|
||||
try!(write!(self.writer, "{}", sep));
|
||||
write!(self.writer, "{}", sep)?;
|
||||
} else if let Some(l) = arg.long() {
|
||||
if arg.short().is_some() {
|
||||
try!(write!(self.writer, ", "));
|
||||
write!(self.writer, ", ")?;
|
||||
}
|
||||
try!(color!(self, "--{}", l, good));
|
||||
color!(self, "--{}", l, good)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -300,33 +300,33 @@ impl<'a> Help<'a> {
|
|||
if let Some(vec) = arg.val_names() {
|
||||
let mut it = vec.iter().peekable();
|
||||
while let Some((_, val)) = it.next() {
|
||||
try!(color!(self, "<{}>", val, good));
|
||||
color!(self, "<{}>", val, good)?;
|
||||
if it.peek().is_some() {
|
||||
try!(write!(self.writer, " "));
|
||||
write!(self.writer, " ")?;
|
||||
}
|
||||
}
|
||||
let num = vec.len();
|
||||
if arg.is_set(ArgSettings::Multiple) && num == 1 {
|
||||
try!(color!(self, "...", good));
|
||||
color!(self, "...", good)?;
|
||||
}
|
||||
} else if let Some(num) = arg.num_vals() {
|
||||
let mut it = (0..num).peekable();
|
||||
while let Some(_) = it.next() {
|
||||
try!(color!(self, "<{}>", arg.name(), good));
|
||||
color!(self, "<{}>", arg.name(), good)?;
|
||||
if it.peek().is_some() {
|
||||
try!(write!(self.writer, " "));
|
||||
write!(self.writer, " ")?;
|
||||
}
|
||||
}
|
||||
if arg.is_set(ArgSettings::Multiple) && num == 1 {
|
||||
try!(color!(self, "...", good));
|
||||
color!(self, "...", good)?;
|
||||
}
|
||||
} else if arg.has_switch() {
|
||||
try!(color!(self, "<{}>", arg.name(), good));
|
||||
color!(self, "<{}>", arg.name(), good)?;
|
||||
if arg.is_set(ArgSettings::Multiple) {
|
||||
try!(color!(self, "...", good));
|
||||
color!(self, "...", good)?;
|
||||
}
|
||||
} else {
|
||||
try!(color!(self, "{}", arg, good));
|
||||
color!(self, "{}", arg, good)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,7 +400,7 @@ impl<'a> Help<'a> {
|
|||
} else {
|
||||
sdebugln!("No");
|
||||
}
|
||||
try!(write!(self.writer, "{}", help));
|
||||
write!(self.writer, "{}", help)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ impl<'a> Help<'a> {
|
|||
|
||||
// Is help on next line, if so then indent
|
||||
if nlh || self.force_next_line {
|
||||
try!(write!(self.writer, "\n{}{}{}", TAB, TAB, TAB));
|
||||
write!(self.writer, "\n{}{}{}", TAB, TAB, TAB)?;
|
||||
}
|
||||
|
||||
debug!("Help::help: Too long...");
|
||||
|
@ -442,21 +442,21 @@ impl<'a> Help<'a> {
|
|||
sdebugln!("No");
|
||||
}
|
||||
if let Some(part) = help.lines().next() {
|
||||
try!(write!(self.writer, "{}", part));
|
||||
write!(self.writer, "{}", part)?;
|
||||
}
|
||||
for part in help.lines().skip(1) {
|
||||
try!(write!(self.writer, "\n"));
|
||||
write!(self.writer, "\n")?;
|
||||
if nlh || self.force_next_line {
|
||||
try!(write!(self.writer, "{}{}{}", TAB, TAB, TAB));
|
||||
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);
|
||||
}
|
||||
try!(write!(self.writer, "{}", part));
|
||||
write!(self.writer, "{}", part)?;
|
||||
}
|
||||
if !help.contains('\n') && (nlh || self.force_next_line) {
|
||||
try!(write!(self.writer, "\n"));
|
||||
write!(self.writer, "\n")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -532,40 +532,40 @@ impl<'a> Help<'a> {
|
|||
.flags()
|
||||
.map(as_arg_trait)
|
||||
.chain(parser.opts().map(as_arg_trait));
|
||||
try!(color!(self, "OPTIONS:\n", warning));
|
||||
try!(self.write_args(opts_flags));
|
||||
color!(self, "OPTIONS:\n", warning)?;
|
||||
self.write_args(opts_flags)?;
|
||||
first = false;
|
||||
} else {
|
||||
if flags {
|
||||
try!(color!(self, "FLAGS:\n", warning));
|
||||
try!(self.write_args(parser.flags().map(as_arg_trait)));
|
||||
color!(self, "FLAGS:\n", warning)?;
|
||||
self.write_args(parser.flags().map(as_arg_trait))?;
|
||||
first = false;
|
||||
}
|
||||
if opts {
|
||||
if !first {
|
||||
try!(self.writer.write_all(b"\n\n"));
|
||||
self.writer.write_all(b"\n\n")?;
|
||||
}
|
||||
try!(color!(self, "OPTIONS:\n", warning));
|
||||
try!(self.write_args(parser.opts().map(as_arg_trait)));
|
||||
color!(self, "OPTIONS:\n", warning)?;
|
||||
self.write_args(parser.opts().map(as_arg_trait))?;
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
if pos {
|
||||
if !first {
|
||||
try!(self.writer.write_all(b"\n\n"));
|
||||
self.writer.write_all(b"\n\n")?;
|
||||
}
|
||||
try!(color!(self, "ARGS:\n", warning));
|
||||
try!(self.write_args_unsorted(parser.positionals().map(as_arg_trait)));
|
||||
color!(self, "ARGS:\n", warning)?;
|
||||
self.write_args_unsorted(parser.positionals().map(as_arg_trait))?;
|
||||
first = false;
|
||||
}
|
||||
|
||||
if subcmds {
|
||||
if !first {
|
||||
try!(self.writer.write_all(b"\n\n"));
|
||||
self.writer.write_all(b"\n\n")?;
|
||||
}
|
||||
try!(color!(self, "SUBCOMMANDS:\n", warning));
|
||||
try!(self.write_subcommands(parser));
|
||||
color!(self, "SUBCOMMANDS:\n", warning)?;
|
||||
self.write_subcommands(parser)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -595,9 +595,9 @@ impl<'a> Help<'a> {
|
|||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
try!(self.writer.write_all(b"\n"));
|
||||
self.writer.write_all(b"\n")?;
|
||||
}
|
||||
try!(self.write_arg(sc));
|
||||
self.write_arg(sc)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -606,7 +606,7 @@ impl<'a> Help<'a> {
|
|||
/// Writes version of a Parser Object to the wrapped stream.
|
||||
fn write_version(&mut self, parser: &Parser) -> io::Result<()> {
|
||||
debugln!("Help::write_version;");
|
||||
try!(write!(self.writer, "{}", parser.meta.version.unwrap_or("")));
|
||||
write!(self.writer, "{}", parser.meta.version.unwrap_or(""))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -617,13 +617,13 @@ impl<'a> Help<'a> {
|
|||
() => {{
|
||||
let mut name = parser.meta.name.clone();
|
||||
name = name.replace("{n}", "\n");
|
||||
try!(color!(self, wrap_help(&name, self.term_w), good));
|
||||
color!(self, wrap_help(&name, self.term_w), good)?;
|
||||
}};
|
||||
}
|
||||
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
|
||||
try!(color!(self, bn.replace(" ", "-"), good))
|
||||
color!(self, bn.replace(" ", "-"), good)?
|
||||
} else {
|
||||
write_name!();
|
||||
}
|
||||
|
@ -637,23 +637,23 @@ impl<'a> Help<'a> {
|
|||
pub fn write_default_help(&mut self, parser: &Parser) -> ClapResult<()> {
|
||||
debugln!("Help::write_default_help;");
|
||||
if let Some(h) = parser.meta.pre_help {
|
||||
try!(self.write_before_after_help(h));
|
||||
try!(self.writer.write_all(b"\n\n"));
|
||||
self.write_before_after_help(h)?;
|
||||
self.writer.write_all(b"\n\n")?;
|
||||
}
|
||||
|
||||
macro_rules! write_thing {
|
||||
($thing:expr) => {{
|
||||
let mut owned_thing = $thing.to_owned();
|
||||
owned_thing = owned_thing.replace("{n}", "\n");
|
||||
try!(write!(self.writer, "{}\n",
|
||||
wrap_help(&owned_thing, self.term_w)))
|
||||
write!(self.writer, "{}\n",
|
||||
wrap_help(&owned_thing, self.term_w))?
|
||||
}};
|
||||
}
|
||||
// Print the version
|
||||
try!(self.write_bin_name(parser));
|
||||
try!(self.writer.write_all(b" "));
|
||||
try!(self.write_version(parser));
|
||||
try!(self.writer.write_all(b"\n"));
|
||||
self.write_bin_name(parser)?;
|
||||
self.writer.write_all(b" ")?;
|
||||
self.write_version(parser)?;
|
||||
self.writer.write_all(b"\n")?;
|
||||
if let Some(author) = parser.meta.author {
|
||||
write_thing!(author)
|
||||
}
|
||||
|
@ -661,11 +661,11 @@ impl<'a> Help<'a> {
|
|||
write_thing!(about)
|
||||
}
|
||||
|
||||
try!(color!(self, "\nUSAGE:", warning));
|
||||
try!(write!(self.writer,
|
||||
color!(self, "\nUSAGE:", warning)?;
|
||||
write!(self.writer,
|
||||
"\n{}{}\n\n",
|
||||
TAB,
|
||||
usage::create_usage_no_title(parser, &[])));
|
||||
usage::create_usage_no_title(parser, &[]))?;
|
||||
|
||||
let flags = parser.has_flags();
|
||||
let pos = parser.has_positionals();
|
||||
|
@ -673,14 +673,14 @@ impl<'a> Help<'a> {
|
|||
let subcmds = parser.has_subcommands();
|
||||
|
||||
if flags || opts || pos || subcmds {
|
||||
try!(self.write_all_args(parser));
|
||||
self.write_all_args(parser)?;
|
||||
}
|
||||
|
||||
if let Some(h) = parser.meta.more_help {
|
||||
if flags || opts || pos || subcmds {
|
||||
try!(self.writer.write_all(b"\n\n"));
|
||||
self.writer.write_all(b"\n\n")?;
|
||||
}
|
||||
try!(self.write_before_after_help(h));
|
||||
self.write_before_after_help(h)?;
|
||||
}
|
||||
|
||||
self.writer.flush().map_err(Error::from)
|
||||
|
@ -841,66 +841,66 @@ impl<'a> Help<'a> {
|
|||
});
|
||||
match &tag_buf.get_ref()[0..tag_length] {
|
||||
b"?" => {
|
||||
try!(self.writer.write_all(b"Could not decode tag name"));
|
||||
self.writer.write_all(b"Could not decode tag name")?;
|
||||
}
|
||||
b"bin" => {
|
||||
try!(self.write_bin_name(parser));
|
||||
self.write_bin_name(parser)?;
|
||||
}
|
||||
b"version" => {
|
||||
try!(write!(self.writer,
|
||||
write!(self.writer,
|
||||
"{}",
|
||||
parser.meta.version.unwrap_or("unknown version")));
|
||||
parser.meta.version.unwrap_or("unknown version"))?;
|
||||
}
|
||||
b"author" => {
|
||||
try!(write!(self.writer,
|
||||
write!(self.writer,
|
||||
"{}",
|
||||
parser.meta.author.unwrap_or("unknown author")));
|
||||
parser.meta.author.unwrap_or("unknown author"))?;
|
||||
}
|
||||
b"about" => {
|
||||
try!(write!(self.writer,
|
||||
write!(self.writer,
|
||||
"{}",
|
||||
parser.meta.about.unwrap_or("unknown about")));
|
||||
parser.meta.about.unwrap_or("unknown about"))?;
|
||||
}
|
||||
b"usage" => {
|
||||
try!(write!(self.writer, "{}", usage::create_usage_no_title(parser, &[])));
|
||||
write!(self.writer, "{}", usage::create_usage_no_title(parser, &[]))?;
|
||||
}
|
||||
b"all-args" => {
|
||||
try!(self.write_all_args(parser));
|
||||
self.write_all_args(parser)?;
|
||||
}
|
||||
b"unified" => {
|
||||
let opts_flags = parser
|
||||
.flags()
|
||||
.map(as_arg_trait)
|
||||
.chain(parser.opts().map(as_arg_trait));
|
||||
try!(self.write_args(opts_flags));
|
||||
self.write_args(opts_flags)?;
|
||||
}
|
||||
b"flags" => {
|
||||
try!(self.write_args(parser.flags().map(as_arg_trait)));
|
||||
self.write_args(parser.flags().map(as_arg_trait))?;
|
||||
}
|
||||
b"options" => {
|
||||
try!(self.write_args(parser.opts().map(as_arg_trait)));
|
||||
self.write_args(parser.opts().map(as_arg_trait))?;
|
||||
}
|
||||
b"positionals" => {
|
||||
try!(self.write_args(parser.positionals().map(as_arg_trait)));
|
||||
self.write_args(parser.positionals().map(as_arg_trait))?;
|
||||
}
|
||||
b"subcommands" => {
|
||||
try!(self.write_subcommands(parser));
|
||||
self.write_subcommands(parser)?;
|
||||
}
|
||||
b"after-help" => {
|
||||
try!(write!(self.writer,
|
||||
write!(self.writer,
|
||||
"{}",
|
||||
parser.meta.more_help.unwrap_or("unknown after-help")));
|
||||
parser.meta.more_help.unwrap_or("unknown after-help"))?;
|
||||
}
|
||||
b"before-help" => {
|
||||
try!(write!(self.writer,
|
||||
write!(self.writer,
|
||||
"{}",
|
||||
parser.meta.pre_help.unwrap_or("unknown before-help")));
|
||||
parser.meta.pre_help.unwrap_or("unknown before-help"))?;
|
||||
}
|
||||
// Unknown tag, write it back.
|
||||
r => {
|
||||
try!(self.writer.write_all(b"{"));
|
||||
try!(self.writer.write_all(r));
|
||||
try!(self.writer.write_all(b"}"));
|
||||
self.writer.write_all(b"{")?;
|
||||
self.writer.write_all(r)?;
|
||||
self.writer.write_all(b"}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ macro_rules! parse_positional {
|
|||
$pos_counter == $_self.positionals.len()) {
|
||||
$_self.settings.set(AS::TrailingValues);
|
||||
}
|
||||
let _ = try!($_self.add_val_to_arg($p, &$arg_os, $matcher));
|
||||
let _ = $_self.add_val_to_arg($p, &$arg_os, $matcher)?;
|
||||
|
||||
$matcher.inc_occurrence_of($p.b.name);
|
||||
let _ = $_self.groups_for_arg($p.b.name)
|
||||
|
|
|
@ -860,7 +860,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
if is_match {
|
||||
let sc_name = sc_name.expect(INTERNAL_ERROR_MSG);
|
||||
if sc_name == "help" && self.is_set(AS::NeedsSubcommandHelp) {
|
||||
try!(self.parse_help_subcommand(it));
|
||||
self.parse_help_subcommand(it)?;
|
||||
}
|
||||
subcmd_name = Some(sc_name.to_owned());
|
||||
break;
|
||||
|
@ -875,12 +875,12 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
.find(|o| o.b.name == name)
|
||||
.expect(INTERNAL_ERROR_MSG);
|
||||
// get the OptBuilder so we can check the settings
|
||||
needs_val_of = try!(self.add_val_to_arg(arg, &arg_os, matcher));
|
||||
needs_val_of = self.add_val_to_arg(arg, &arg_os, matcher)?;
|
||||
// get the next value from the iterator
|
||||
continue;
|
||||
}
|
||||
} else if arg_os.starts_with(b"--") {
|
||||
needs_val_of = try!(self.parse_long_arg(matcher, &arg_os));
|
||||
needs_val_of = self.parse_long_arg(matcher, &arg_os)?;
|
||||
debugln!("Parser:get_matches_with: After parse_long_arg {:?}",
|
||||
needs_val_of);
|
||||
match needs_val_of {
|
||||
|
@ -893,7 +893,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 = try!(self.parse_short_arg(matcher, &arg_os));
|
||||
needs_val_of = self.parse_short_arg(matcher, &arg_os)?;
|
||||
// If it's None, we then check if one of those two AppSettings was set
|
||||
debugln!("Parser:get_matches_with: After parse_short_arg {:?}",
|
||||
needs_val_of);
|
||||
|
@ -1059,7 +1059,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
.name
|
||||
.clone()
|
||||
};
|
||||
try!(self.parse_subcommand(&*sc_name, matcher, it));
|
||||
self.parse_subcommand(&*sc_name, matcher, it)?;
|
||||
} else if self.is_set(AS::SubcommandRequired) {
|
||||
let bn = self.meta.bin_name.as_ref().unwrap_or(&self.meta.name);
|
||||
return Err(Error::missing_subcommand(bn,
|
||||
|
@ -1068,7 +1068,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
} else if self.is_set(AS::SubcommandRequiredElseHelp) {
|
||||
debugln!("Parser::get_matches_with: SubcommandRequiredElseHelp=true");
|
||||
let mut out = vec![];
|
||||
try!(self.write_help_err(&mut out));
|
||||
self.write_help_err(&mut out)?;
|
||||
return Err(Error {
|
||||
message: String::from_utf8_lossy(&*out).into_owned(),
|
||||
kind: ErrorKind::MissingArgumentOrSubcommand,
|
||||
|
@ -1167,7 +1167,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
debugln!("Parser::parse_subcommand: About to parse sc={}",
|
||||
sc.p.meta.name);
|
||||
debugln!("Parser::parse_subcommand: sc settings={:#?}", sc.p.settings);
|
||||
try!(sc.p.get_matches_with(&mut sc_matcher, it));
|
||||
sc.p.get_matches_with(&mut sc_matcher, it)?;
|
||||
matcher.subcommand(SubCommand {
|
||||
name: sc.p.meta.name.clone(),
|
||||
matches: sc_matcher.into(),
|
||||
|
@ -1399,7 +1399,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
debugln!("Parser::parse_long_arg: Found valid opt '{}'",
|
||||
opt.to_string());
|
||||
self.settings.set(AS::ValidArgFound);
|
||||
let ret = try!(self.parse_opt(val, opt, val.is_some(), matcher));
|
||||
let ret = self.parse_opt(val, opt, val.is_some(), matcher)?;
|
||||
if self.cache.map_or(true, |name| name != opt.b.name) {
|
||||
arg_post_processing!(self, opt, matcher);
|
||||
self.cache = Some(opt.b.name);
|
||||
|
@ -1412,9 +1412,9 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
self.settings.set(AS::ValidArgFound);
|
||||
// Only flags could be help or version, and we need to check the raw long
|
||||
// so this is the first point to check
|
||||
try!(self.check_for_help_and_version_str(arg));
|
||||
self.check_for_help_and_version_str(arg)?;
|
||||
|
||||
try!(self.parse_flag(flag, matcher));
|
||||
self.parse_flag(flag, matcher)?;
|
||||
|
||||
// Handle conflicts, requirements, etc.
|
||||
// if self.cache.map_or(true, |name| name != flag.b.name) {
|
||||
|
@ -1486,7 +1486,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
};
|
||||
|
||||
// Default to "we're expecting a value later"
|
||||
let ret = try!(self.parse_opt(val, opt, false, matcher));
|
||||
let ret = self.parse_opt(val, opt, false, matcher)?;
|
||||
|
||||
if self.cache.map_or(true, |name| name != opt.b.name) {
|
||||
arg_post_processing!(self, opt, matcher);
|
||||
|
@ -1498,8 +1498,8 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
debugln!("Parser::parse_short_arg:iter:{}: Found valid flag", c);
|
||||
self.settings.set(AS::ValidArgFound);
|
||||
// Only flags can be help or version
|
||||
try!(self.check_for_help_and_version_char(c));
|
||||
ret = try!(self.parse_flag(flag, matcher));
|
||||
self.check_for_help_and_version_char(c)?;
|
||||
ret = self.parse_flag(flag, matcher)?;
|
||||
|
||||
// Handle conflicts, requirements, overrides, etc.
|
||||
// Must be called here due to mutablilty
|
||||
|
@ -1545,7 +1545,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
debugln!("Parser::parse_opt: {:?} contains '='...{:?}",
|
||||
fv,
|
||||
fv.starts_with(&[b'=']));
|
||||
try!(self.add_val_to_arg(opt, v, matcher));
|
||||
self.add_val_to_arg(opt, v, matcher)?;
|
||||
} else if opt.is_set(ArgSettings::RequireEquals) && !opt.is_set(ArgSettings::EmptyValues) {
|
||||
sdebugln!("None, but requires equals...Error");
|
||||
return Err(Error::empty_value(opt,
|
||||
|
@ -1586,11 +1586,11 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
if !(self.is_set(AS::TrailingValues) && self.is_set(AS::DontDelimitTrailingValues)) {
|
||||
if let Some(delim) = arg.val_delim() {
|
||||
if val.is_empty_() {
|
||||
Ok(try!(self.add_single_val_to_arg(arg, val, matcher)))
|
||||
Ok(self.add_single_val_to_arg(arg, val, matcher)?)
|
||||
} else {
|
||||
let mut iret = ParseResult::ValuesDone;
|
||||
for v in val.split(delim as u32 as u8) {
|
||||
iret = try!(self.add_single_val_to_arg(arg, v, matcher));
|
||||
iret = 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) ||
|
||||
|
@ -1679,7 +1679,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
|
||||
// Prints the version to the user and exits if quit=true
|
||||
fn print_version<W: Write>(&self, w: &mut W, use_long: bool) -> ClapResult<()> {
|
||||
try!(self.write_version(w, use_long));
|
||||
self.write_version(w, use_long)?;
|
||||
w.flush().map_err(Error::from)
|
||||
}
|
||||
|
||||
|
@ -1728,7 +1728,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
(@default $_self:ident, $a:ident, $m:ident) => {
|
||||
if let Some(ref val) = $a.v.default_val {
|
||||
if $m.get($a.b.name).is_none() {
|
||||
try!($_self.add_val_to_arg($a, OsStr::new(val), $m));
|
||||
$_self.add_val_to_arg($a, OsStr::new(val), $m)?;
|
||||
|
||||
if $_self.cache.map_or(true, |name| name != $a.name()) {
|
||||
arg_post_processing!($_self, $a, $m);
|
||||
|
@ -1752,7 +1752,7 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
false
|
||||
};
|
||||
if add {
|
||||
try!($_self.add_val_to_arg($a, OsStr::new(default), $m));
|
||||
$_self.add_val_to_arg($a, OsStr::new(default), $m)?;
|
||||
if $_self.cache.map_or(true, |name| name != $a.name()) {
|
||||
arg_post_processing!($_self, $a, $m);
|
||||
$_self.cache = Some($a.name());
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
|
|||
-> ClapResult<()> {
|
||||
debugln!("Validator::validate;");
|
||||
let mut reqs_validated = false;
|
||||
try!(self.0.add_defaults(matcher));
|
||||
self.0.add_defaults(matcher)?;
|
||||
if let ParseResult::Opt(a) = needs_val_of {
|
||||
debugln!("Validator::validate: needs_val_of={:?}", a);
|
||||
let o = self.0
|
||||
|
@ -36,7 +36,7 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
|
|||
.iter()
|
||||
.find(|o| o.b.name == a)
|
||||
.expect(INTERNAL_ERROR_MSG);
|
||||
try!(self.validate_required(matcher));
|
||||
self.validate_required(matcher)?;
|
||||
reqs_validated = true;
|
||||
let should_err = if let Some(v) = matcher.0.args.get(&*o.b.name) {
|
||||
v.vals.is_empty() && !(o.v.min_vals.is_some() && o.v.min_vals.unwrap() == 0)
|
||||
|
@ -53,18 +53,18 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
|
|||
if matcher.is_empty() && matcher.subcommand_name().is_none() &&
|
||||
self.0.is_set(AS::ArgRequiredElseHelp) {
|
||||
let mut out = vec![];
|
||||
try!(self.0.write_help_err(&mut out));
|
||||
self.0.write_help_err(&mut out)?;
|
||||
return Err(Error {
|
||||
message: String::from_utf8_lossy(&*out).into_owned(),
|
||||
kind: ErrorKind::MissingArgumentOrSubcommand,
|
||||
info: None,
|
||||
});
|
||||
}
|
||||
try!(self.validate_blacklist(matcher));
|
||||
self.validate_blacklist(matcher)?;
|
||||
if !(self.0.is_set(AS::SubcommandsNegateReqs) && subcmd_name.is_some()) && !reqs_validated {
|
||||
try!(self.validate_required(matcher));
|
||||
self.validate_required(matcher)?;
|
||||
}
|
||||
try!(self.validate_matched_args(matcher));
|
||||
self.validate_matched_args(matcher)?;
|
||||
matcher.usage(usage::create_usage_with_title(self.0, &[]));
|
||||
|
||||
Ok(())
|
||||
|
@ -192,18 +192,18 @@ impl<'a, 'b, 'z> Validator<'a, 'b, 'z> {
|
|||
name,
|
||||
ma.vals);
|
||||
if let Some(opt) = find_by_name!(self.0, *name, opts, iter) {
|
||||
try!(self.validate_arg_num_vals(opt, ma, matcher));
|
||||
try!(self.validate_values(opt, ma, matcher));
|
||||
try!(self.validate_arg_requires(opt, ma, matcher));
|
||||
try!(self.validate_arg_num_occurs(opt, ma, matcher));
|
||||
self.validate_arg_num_vals(opt, ma, matcher)?;
|
||||
self.validate_values(opt, ma, matcher)?;
|
||||
self.validate_arg_requires(opt, ma, matcher)?;
|
||||
self.validate_arg_num_occurs(opt, ma, matcher)?;
|
||||
} else if let Some(flag) = find_by_name!(self.0, *name, flags, iter) {
|
||||
try!(self.validate_arg_requires(flag, ma, matcher));
|
||||
try!(self.validate_arg_num_occurs(flag, ma, matcher));
|
||||
self.validate_arg_requires(flag, ma, matcher)?;
|
||||
self.validate_arg_num_occurs(flag, ma, matcher)?;
|
||||
} else if let Some(pos) = find_by_name!(self.0, *name, positionals, values) {
|
||||
try!(self.validate_arg_num_vals(pos, ma, matcher));
|
||||
try!(self.validate_arg_num_occurs(pos, ma, matcher));
|
||||
try!(self.validate_values(pos, ma, matcher));
|
||||
try!(self.validate_arg_requires(pos, ma, matcher));
|
||||
self.validate_arg_num_vals(pos, ma, matcher)?;
|
||||
self.validate_arg_num_occurs(pos, ma, matcher)?;
|
||||
self.validate_values(pos, ma, matcher)?;
|
||||
self.validate_arg_requires(pos, ma, matcher)?;
|
||||
} else {
|
||||
let grp = self.0
|
||||
.groups
|
||||
|
|
|
@ -47,9 +47,9 @@ impl<'a, 'b> From<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.s.long {
|
||||
try!(write!(f, "--{}", l));
|
||||
write!(f, "--{}", l)?;
|
||||
} else {
|
||||
try!(write!(f, "-{}", self.s.short.unwrap()));
|
||||
write!(f, "-{}", self.s.short.unwrap())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -57,44 +57,44 @@ impl<'n, 'e> Display for OptBuilder<'n, 'e> {
|
|||
};
|
||||
// Write the name such --long or -l
|
||||
if let Some(l) = self.s.long {
|
||||
try!(write!(f, "--{}{}", l, sep));
|
||||
write!(f, "--{}{}", l, sep)?;
|
||||
} else {
|
||||
try!(write!(f, "-{}{}", self.s.short.unwrap(), sep));
|
||||
write!(f, "-{}{}", self.s.short.unwrap(), sep)?;
|
||||
}
|
||||
|
||||
// Write the values such as <name1> <name2>
|
||||
if let Some(ref vec) = self.v.val_names {
|
||||
let mut it = vec.iter().peekable();
|
||||
while let Some((_, val)) = it.next() {
|
||||
try!(write!(f, "<{}>", val));
|
||||
write!(f, "<{}>", val)?;
|
||||
if it.peek().is_some() {
|
||||
try!(write!(f, " "));
|
||||
write!(f, " ")?;
|
||||
}
|
||||
}
|
||||
let num = vec.len();
|
||||
if self.is_set(ArgSettings::Multiple) && num == 1 {
|
||||
try!(write!(f, "..."));
|
||||
write!(f, "...")?;
|
||||
}
|
||||
} else if let Some(num) = self.v.num_vals {
|
||||
let mut it = (0..num).peekable();
|
||||
while let Some(_) = it.next() {
|
||||
try!(write!(f, "<{}>", self.b.name));
|
||||
write!(f, "<{}>", self.b.name)?;
|
||||
if it.peek().is_some() {
|
||||
try!(write!(f, " "));
|
||||
write!(f, " ")?;
|
||||
}
|
||||
}
|
||||
if self.is_set(ArgSettings::Multiple) && num == 1 {
|
||||
try!(write!(f, "..."));
|
||||
write!(f, "...")?;
|
||||
}
|
||||
} else {
|
||||
try!(write!(f,
|
||||
"<{}>{}",
|
||||
self.b.name,
|
||||
if self.is_set(ArgSettings::Multiple) {
|
||||
"..."
|
||||
} else {
|
||||
""
|
||||
}));
|
||||
write!(f,
|
||||
"<{}>{}",
|
||||
self.b.name,
|
||||
if self.is_set(ArgSettings::Multiple) {
|
||||
"..."
|
||||
} else {
|
||||
""
|
||||
})?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -94,18 +94,18 @@ 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.v.val_names {
|
||||
try!(write!(f,
|
||||
"{}",
|
||||
names
|
||||
.values()
|
||||
.map(|n| format!("<{}>", n))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")));
|
||||
write!(f,
|
||||
"{}",
|
||||
names
|
||||
.values()
|
||||
.map(|n| format!("<{}>", n))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "))?;
|
||||
} else {
|
||||
try!(write!(f, "<{}>", self.b.name));
|
||||
write!(f, "<{}>", self.b.name)?;
|
||||
}
|
||||
if self.b.settings.is_set(ArgSettings::Multiple) && (self.v.val_names.is_none() || self.v.val_names.as_ref().unwrap().len() == 1) {
|
||||
try!(write!(f, "..."));
|
||||
write!(f, "...")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -811,7 +811,7 @@ macro_rules! write_nspaces {
|
|||
($dst:expr, $num:expr) => ({
|
||||
debugln!("write_spaces!: num={}", $num);
|
||||
for _ in 0..$num {
|
||||
try!($dst.write_all(b" "));
|
||||
$dst.write_all(b" ")?;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue