mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
chore: rustfmt run
This commit is contained in:
parent
ba7a4e33e1
commit
80cc68748d
28 changed files with 170 additions and 281 deletions
|
@ -21,14 +21,10 @@ use vec_map::VecMap;
|
|||
|
||||
#[cfg(not(feature = "wrap_help"))]
|
||||
mod term_size {
|
||||
pub fn dimensions() -> Option<(usize, usize)> {
|
||||
None
|
||||
}
|
||||
pub fn dimensions() -> Option<(usize, usize)> { None }
|
||||
}
|
||||
|
||||
fn str_width(s: &str) -> usize {
|
||||
UnicodeWidthStr::width(s)
|
||||
}
|
||||
fn str_width(s: &str) -> usize { UnicodeWidthStr::width(s) }
|
||||
|
||||
const TAB: &'static str = " ";
|
||||
|
||||
|
@ -42,19 +38,13 @@ trait ArgWithOrder<'b, 'c>: ArgWithDisplay<'b, 'c> + DispOrder {
|
|||
impl<'b, 'c, T> ArgWithOrder<'b, 'c> for T
|
||||
where T: ArgWithDisplay<'b, 'c> + DispOrder
|
||||
{
|
||||
fn as_base(&self) -> &ArgWithDisplay<'b, 'c> {
|
||||
self
|
||||
}
|
||||
fn as_base(&self) -> &ArgWithDisplay<'b, 'c> { self }
|
||||
}
|
||||
|
||||
fn as_arg_trait<'a, 'b, T: ArgWithOrder<'a, 'b>>(x: &T) -> &ArgWithOrder<'a, 'b> {
|
||||
x
|
||||
}
|
||||
fn as_arg_trait<'a, 'b, T: ArgWithOrder<'a, 'b>>(x: &T) -> &ArgWithOrder<'a, 'b> { x }
|
||||
|
||||
impl<'b, 'c> DispOrder for App<'b, 'c> {
|
||||
fn disp_ord(&self) -> usize {
|
||||
999
|
||||
}
|
||||
fn disp_ord(&self) -> usize { 999 }
|
||||
}
|
||||
|
||||
macro_rules! color {
|
||||
|
|
|
@ -41,12 +41,8 @@ impl<'b> Default for AppMeta<'b> {
|
|||
}
|
||||
|
||||
impl<'b> AppMeta<'b> {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
pub fn with_name(s: String) -> Self {
|
||||
AppMeta { name: s, ..Default::default() }
|
||||
}
|
||||
pub fn new() -> Self { Default::default() }
|
||||
pub fn with_name(s: String) -> Self { AppMeta { name: s, ..Default::default() } }
|
||||
}
|
||||
|
||||
impl<'b> Clone for AppMeta<'b> {
|
||||
|
|
|
@ -21,8 +21,7 @@ use app::App;
|
|||
use app::help::Help;
|
||||
use app::meta::AppMeta;
|
||||
use app::settings::{AppFlags, AppSettings};
|
||||
use args::{AnyArg, ArgMatcher, Base, Switched};
|
||||
use args::{Arg, ArgKind, ArgGroup, FlagBuilder, OptBuilder, PosBuilder};
|
||||
use args::{AnyArg, ArgMatcher, Base, Switched, Arg, ArgGroup, FlagBuilder, OptBuilder, PosBuilder};
|
||||
use args::MatchedArg;
|
||||
use args::settings::ArgSettings;
|
||||
use completions::ComplGen;
|
||||
|
@ -33,9 +32,6 @@ use osstringext::OsStrExt2;
|
|||
use completions::Shell;
|
||||
use suggestions;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
struct ArgId(usize, ArgKind);
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[doc(hidden)]
|
||||
pub struct Parser<'a, 'b>
|
||||
|
|
|
@ -41,9 +41,7 @@ bitflags! {
|
|||
pub struct AppFlags(Flags);
|
||||
|
||||
impl Clone for AppFlags {
|
||||
fn clone(&self) -> Self {
|
||||
AppFlags(self.0)
|
||||
}
|
||||
fn clone(&self) -> Self { AppFlags(self.0) }
|
||||
}
|
||||
|
||||
impl Default for AppFlags {
|
||||
|
@ -53,9 +51,7 @@ impl Default for AppFlags {
|
|||
}
|
||||
|
||||
impl AppFlags {
|
||||
pub fn new() -> Self {
|
||||
AppFlags::default()
|
||||
}
|
||||
pub fn new() -> Self { AppFlags::default() }
|
||||
|
||||
impl_settings! { AppSettings,
|
||||
ArgRequiredElseHelp => A_REQUIRED_ELSE_HELP,
|
||||
|
@ -363,7 +359,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,7 +663,6 @@ pub enum AppSettings {
|
|||
|
||||
#[doc(hidden)]
|
||||
LowIndexMultiplePositional,
|
||||
|
||||
}
|
||||
|
||||
impl FromStr for AppSettings {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -126,9 +126,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
/// ```
|
||||
/// [`Arg::takes_value(true)`]: ./struct.Arg.html#method.takes_value
|
||||
/// [`Arg`]: ./struct.Arg.html
|
||||
pub fn with_name(n: &'a str) -> Self {
|
||||
Arg { name: n, ..Default::default() }
|
||||
}
|
||||
pub fn with_name(n: &'a str) -> Self { Arg { name: n, ..Default::default() } }
|
||||
|
||||
/// Creates a new instance of [`Arg`] from a .yml (YAML) file.
|
||||
///
|
||||
|
@ -2522,9 +2520,7 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
|
||||
/// Checks if one of the [`ArgSettings`] settings is set for the argument
|
||||
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
||||
pub fn is_set(&self, s: ArgSettings) -> bool {
|
||||
self.settings.is_set(s)
|
||||
}
|
||||
pub fn is_set(&self, s: ArgSettings) -> bool { self.settings.is_set(s) }
|
||||
|
||||
/// Sets one of the [`ArgSettings`] settings for the argument
|
||||
/// [`ArgSettings`]: ./enum.ArgSettings.html
|
||||
|
@ -2541,14 +2537,10 @@ impl<'a, 'b> Arg<'a, 'b> {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn setb(&mut self, s: ArgSettings) {
|
||||
self.settings.set(s);
|
||||
}
|
||||
pub fn setb(&mut self, s: ArgSettings) { self.settings.set(s); }
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn unsetb(&mut self, s: ArgSettings) {
|
||||
self.settings.unset(s);
|
||||
}
|
||||
pub fn unsetb(&mut self, s: ArgSettings) { self.settings.unset(s); }
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>> for Arg<'a, 'b> {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use args::{ArgSettings, Arg, ArgFlags, ArgKind};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Base<'a, 'b> where 'a: 'b {
|
||||
pub struct Base<'a, 'b>
|
||||
where 'a: 'b
|
||||
{
|
||||
pub name: &'a str,
|
||||
pub id: usize,
|
||||
pub kind: ArgKind,
|
||||
|
@ -32,19 +34,15 @@ impl<'n, 'e> Default for Base<'n, 'e> {
|
|||
}
|
||||
|
||||
impl<'n, 'e> Base<'n, 'e> {
|
||||
pub fn new(name: &'n str) -> Self {
|
||||
Base { name: name, ..Default::default() }
|
||||
}
|
||||
pub fn new(name: &'n str) -> Self { Base { name: name, ..Default::default() } }
|
||||
|
||||
pub fn set(&mut self, s: ArgSettings) {
|
||||
self.settings.set(s);
|
||||
}
|
||||
pub fn set(&mut self, s: ArgSettings) { self.settings.set(s); }
|
||||
}
|
||||
|
||||
impl<'n, 'e, 'z> From<&'z Arg<'n, 'e>> for Base<'n, 'e> {
|
||||
fn from(a: &'z Arg<'n, 'e>) -> Self {
|
||||
Base {
|
||||
name: a.name,
|
||||
name: a.name,
|
||||
help: a.help,
|
||||
id: 0,
|
||||
kind: ArgKind::Pos,
|
||||
|
|
|
@ -10,4 +10,4 @@ mod positional;
|
|||
mod option;
|
||||
mod base;
|
||||
mod valued;
|
||||
mod switched;
|
||||
mod switched;
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<'n, 'e, 'z> From<&'z Arg<'n, 'e>> for Switched<'e> {
|
|||
long: a.long,
|
||||
aliases: a.aliases.clone(),
|
||||
disp_ord: a.disp_ord,
|
||||
.. Default::default()
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ use Arg;
|
|||
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[derive(Clone)]
|
||||
pub struct Valued<'a, 'b> where 'a: 'b {
|
||||
pub struct Valued<'a, 'b>
|
||||
where 'a: 'b
|
||||
{
|
||||
pub possible_vals: Option<Vec<&'b str>>,
|
||||
pub val_names: Option<VecMap<&'b str>>,
|
||||
pub num_vals: Option<u64>,
|
||||
|
|
|
@ -16,27 +16,17 @@ use args::settings::ArgSettings;
|
|||
pub struct ArgMatcher<'a>(pub ArgMatches<'a>);
|
||||
|
||||
impl<'a> Default for ArgMatcher<'a> {
|
||||
fn default() -> Self {
|
||||
ArgMatcher(ArgMatches::default())
|
||||
}
|
||||
fn default() -> Self { ArgMatcher(ArgMatches::default()) }
|
||||
}
|
||||
|
||||
impl<'a> ArgMatcher<'a> {
|
||||
pub fn new() -> Self {
|
||||
ArgMatcher::default()
|
||||
}
|
||||
pub fn new() -> Self { ArgMatcher::default() }
|
||||
|
||||
pub fn get_mut(&mut self, arg: &str) -> Option<&mut MatchedArg> {
|
||||
self.0.args.get_mut(arg)
|
||||
}
|
||||
pub fn get_mut(&mut self, arg: &str) -> Option<&mut MatchedArg> { self.0.args.get_mut(arg) }
|
||||
|
||||
pub fn get(&self, arg: &str) -> Option<&MatchedArg> {
|
||||
self.0.args.get(arg)
|
||||
}
|
||||
pub fn get(&self, arg: &str) -> Option<&MatchedArg> { self.0.args.get(arg) }
|
||||
|
||||
pub fn remove(&mut self, arg: &str) {
|
||||
self.0.args.remove(arg);
|
||||
}
|
||||
pub fn remove(&mut self, arg: &str) { self.0.args.remove(arg); }
|
||||
|
||||
pub fn remove_all(&mut self, args: &[&str]) {
|
||||
for &arg in args {
|
||||
|
@ -44,41 +34,23 @@ impl<'a> ArgMatcher<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, name: &'a str) {
|
||||
self.0.args.insert(name, MatchedArg::new());
|
||||
}
|
||||
pub fn insert(&mut self, name: &'a str) { self.0.args.insert(name, MatchedArg::new()); }
|
||||
|
||||
pub fn contains(&self, arg: &str) -> bool {
|
||||
self.0.args.contains_key(arg)
|
||||
}
|
||||
pub fn contains(&self, arg: &str) -> bool { self.0.args.contains_key(arg) }
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.args.is_empty()
|
||||
}
|
||||
pub fn is_empty(&self) -> bool { self.0.args.is_empty() }
|
||||
|
||||
pub fn usage(&mut self, usage: String) {
|
||||
self.0.usage = Some(usage);
|
||||
}
|
||||
pub fn usage(&mut self, usage: String) { self.0.usage = Some(usage); }
|
||||
|
||||
pub fn arg_names(&'a self) -> Vec<&'a str> {
|
||||
self.0.args.keys().map(Deref::deref).collect()
|
||||
}
|
||||
pub fn arg_names(&'a self) -> Vec<&'a str> { self.0.args.keys().map(Deref::deref).collect() }
|
||||
|
||||
pub fn entry(&mut self, arg: &'a str) -> Entry<&'a str, MatchedArg> {
|
||||
self.0.args.entry(arg)
|
||||
}
|
||||
pub fn entry(&mut self, arg: &'a str) -> Entry<&'a str, MatchedArg> { self.0.args.entry(arg) }
|
||||
|
||||
pub fn subcommand(&mut self, sc: SubCommand<'a>) {
|
||||
self.0.subcommand = Some(Box::new(sc));
|
||||
}
|
||||
pub fn subcommand(&mut self, sc: SubCommand<'a>) { self.0.subcommand = Some(Box::new(sc)); }
|
||||
|
||||
pub fn subcommand_name(&self) -> Option<&str> {
|
||||
self.0.subcommand_name()
|
||||
}
|
||||
pub fn subcommand_name(&self) -> Option<&str> { self.0.subcommand_name() }
|
||||
|
||||
pub fn iter(&self) -> Iter<&str, MatchedArg> {
|
||||
self.0.args.iter()
|
||||
}
|
||||
pub fn iter(&self) -> Iter<&str, MatchedArg> { self.0.args.iter() }
|
||||
|
||||
pub fn inc_occurrence_of(&mut self, arg: &'a str) {
|
||||
debugln!("fn=inc_occurrence_of;");
|
||||
|
@ -132,7 +104,5 @@ impl<'a> ArgMatcher<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Into<ArgMatches<'a>> for ArgMatcher<'a> {
|
||||
fn into(self) -> ArgMatches<'a> {
|
||||
self.0
|
||||
}
|
||||
fn into(self) -> ArgMatches<'a> { self.0 }
|
||||
}
|
||||
|
|
|
@ -82,9 +82,7 @@ impl<'a> Default for ArgMatches<'a> {
|
|||
|
||||
impl<'a> ArgMatches<'a> {
|
||||
#[doc(hidden)]
|
||||
pub fn new() -> Self {
|
||||
ArgMatches { ..Default::default() }
|
||||
}
|
||||
pub fn new() -> Self { ArgMatches { ..Default::default() } }
|
||||
|
||||
/// Gets the value of a specific [option] or [positional] argument (i.e. an argument that takes
|
||||
/// an additional value at runtime). If the option wasn't present at runtime
|
||||
|
@ -214,9 +212,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// [`Iterator`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html
|
||||
pub fn values_of<S: AsRef<str>>(&'a self, name: S) -> Option<Values<'a>> {
|
||||
if let Some(arg) = self.args.get(name.as_ref()) {
|
||||
fn to_str_slice(o: &OsString) -> &str {
|
||||
o.to_str().expect(INVALID_UTF8)
|
||||
}
|
||||
fn to_str_slice(o: &OsString) -> &str { o.to_str().expect(INVALID_UTF8) }
|
||||
let to_str_slice: fn(&OsString) -> &str = to_str_slice; // coerce to fn pointer
|
||||
return Some(Values { iter: arg.vals.values().map(to_str_slice) });
|
||||
}
|
||||
|
@ -289,9 +285,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// [`OsString`]: https://doc.rust-lang.org/std/ffi/struct.OsString.html
|
||||
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
|
||||
pub fn values_of_os<S: AsRef<str>>(&'a self, name: S) -> Option<OsValues<'a>> {
|
||||
fn to_str_slice(o: &OsString) -> &OsStr {
|
||||
&*o
|
||||
}
|
||||
fn to_str_slice(o: &OsString) -> &OsStr { &*o }
|
||||
let to_str_slice: fn(&'a OsString) -> &'a OsStr = to_str_slice; // coerce to fn pointer
|
||||
if let Some(arg) = self.args.get(name.as_ref()) {
|
||||
return Some(OsValues { iter: arg.vals.values().map(to_str_slice) });
|
||||
|
@ -533,9 +527,7 @@ impl<'a> ArgMatches<'a> {
|
|||
/// ```
|
||||
/// [`Subcommand`]: ./struct.SubCommand.html
|
||||
/// [`App`]: ./struct.App.html
|
||||
pub fn usage(&self) -> &str {
|
||||
self.usage.as_ref().map_or("", |u| &u[..])
|
||||
}
|
||||
pub fn usage(&self) -> &str { self.usage.as_ref().map_or("", |u| &u[..]) }
|
||||
}
|
||||
|
||||
|
||||
|
@ -568,18 +560,12 @@ pub struct Values<'a> {
|
|||
impl<'a> Iterator for Values<'a> {
|
||||
type Item = &'a str;
|
||||
|
||||
fn next(&mut self) -> Option<&'a str> {
|
||||
self.iter.next()
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
fn next(&mut self) -> Option<&'a str> { self.iter.next() }
|
||||
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
|
||||
}
|
||||
|
||||
impl<'a> DoubleEndedIterator for Values<'a> {
|
||||
fn next_back(&mut self) -> Option<&'a str> {
|
||||
self.iter.next_back()
|
||||
}
|
||||
fn next_back(&mut self) -> Option<&'a str> { self.iter.next_back() }
|
||||
}
|
||||
|
||||
/// An iterator over the key-value pairs of a map.
|
||||
|
@ -608,9 +594,7 @@ impl<'a, V> Iterator for Iter<'a, V> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(self.back - self.front))
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) { (0, Some(self.back - self.front)) }
|
||||
}
|
||||
|
||||
impl<'a, V> DoubleEndedIterator for Iter<'a, V> {
|
||||
|
@ -659,16 +643,10 @@ pub struct OsValues<'a> {
|
|||
impl<'a> Iterator for OsValues<'a> {
|
||||
type Item = &'a OsStr;
|
||||
|
||||
fn next(&mut self) -> Option<&'a OsStr> {
|
||||
self.iter.next()
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iter.size_hint()
|
||||
}
|
||||
fn next(&mut self) -> Option<&'a OsStr> { self.iter.next() }
|
||||
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
|
||||
}
|
||||
|
||||
impl<'a> DoubleEndedIterator for OsValues<'a> {
|
||||
fn next_back(&mut self) -> Option<&'a OsStr> {
|
||||
self.iter.next_back()
|
||||
}
|
||||
fn next_back(&mut self) -> Option<&'a OsStr> { self.iter.next_back() }
|
||||
}
|
||||
|
|
|
@ -128,9 +128,7 @@ impl<'a> ArgGroup<'a> {
|
|||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "yaml")]
|
||||
pub fn from_yaml(y: &'a Yaml) -> ArgGroup<'a> {
|
||||
ArgGroup::from(y.as_hash().unwrap())
|
||||
}
|
||||
pub fn from_yaml(y: &'a Yaml) -> ArgGroup<'a> { ArgGroup::from(y.as_hash().unwrap()) }
|
||||
|
||||
/// Adds an [argument] to this group by name
|
||||
///
|
||||
|
|
|
@ -23,7 +23,5 @@ impl Default for MatchedArg {
|
|||
}
|
||||
|
||||
impl MatchedArg {
|
||||
pub fn new() -> Self {
|
||||
MatchedArg::default()
|
||||
}
|
||||
pub fn new() -> Self { MatchedArg::default() }
|
||||
}
|
||||
|
|
|
@ -27,5 +27,5 @@ pub enum ArgKind {
|
|||
Opt,
|
||||
Pos,
|
||||
Subcmd,
|
||||
Group
|
||||
}
|
||||
Group,
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ bitflags! {
|
|||
pub struct ArgFlags(Flags);
|
||||
|
||||
impl ArgFlags {
|
||||
pub fn new() -> Self {
|
||||
ArgFlags::default()
|
||||
}
|
||||
pub fn new() -> Self { ArgFlags::default() }
|
||||
|
||||
impl_settings!{ArgSettings,
|
||||
Required => REQUIRED,
|
||||
|
@ -47,9 +45,7 @@ impl ArgFlags {
|
|||
}
|
||||
|
||||
impl Default for ArgFlags {
|
||||
fn default() -> Self {
|
||||
ArgFlags(EMPTY_VALS | DELIM_NOT_SET)
|
||||
}
|
||||
fn default() -> Self { ArgFlags(EMPTY_VALS | DELIM_NOT_SET) }
|
||||
}
|
||||
|
||||
/// Various settings that apply to arguments and may be set, unset, and checked via getter/setter
|
||||
|
@ -144,4 +140,4 @@ mod test {
|
|||
ArgSettings::ValueDelimiterNotSet);
|
||||
assert!("hahahaha".parse::<ArgSettings>().is_err());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,7 @@ impl<'a> SubCommand<'a> {
|
|||
/// SubCommand::with_name("config"))
|
||||
/// # ;
|
||||
/// ```
|
||||
pub fn with_name<'b>(name: &str) -> App<'a, 'b> {
|
||||
App::new(name)
|
||||
}
|
||||
pub fn with_name<'b>(name: &str) -> App<'a, 'b> { App::new(name) }
|
||||
|
||||
/// Creates a new instance of a subcommand from a YAML (.yml) document
|
||||
///
|
||||
|
@ -66,7 +64,5 @@ impl<'a> SubCommand<'a> {
|
|||
/// # }
|
||||
/// ```
|
||||
#[cfg(feature = "yaml")]
|
||||
pub fn from_yaml(yaml: &Yaml) -> App {
|
||||
App::from_yaml(yaml)
|
||||
}
|
||||
pub fn from_yaml(yaml: &Yaml) -> App { App::from_yaml(yaml) }
|
||||
}
|
||||
|
|
|
@ -13,13 +13,11 @@ pub struct BashGen<'a, 'b>
|
|||
}
|
||||
|
||||
impl<'a, 'b> BashGen<'a, 'b> {
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self {
|
||||
BashGen { p: p }
|
||||
}
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self { BashGen { p: p } }
|
||||
|
||||
pub fn generate_to<W: Write>(&self, buf: &mut W) {
|
||||
|
||||
w!(buf,
|
||||
w!(buf,
|
||||
format!("_{name}() {{
|
||||
local i cur prev opts cmds
|
||||
COMPREPLY=()
|
||||
|
@ -177,9 +175,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 +187,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);
|
||||
|
|
|
@ -109,4 +109,4 @@ fn gen_fish_inner(root_command: &str, comp_gen: &FishGen, parent_cmds: &str, buf
|
|||
sub_parent_cmds.push_str(&subcommand.p.meta.name);
|
||||
gen_fish_inner(root_command, &sub_comp_gen, &sub_parent_cmds, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,4 +26,4 @@ macro_rules! get_zsh_arg_conflicts {
|
|||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,22 +24,20 @@ pub struct ComplGen<'a, 'b>
|
|||
}
|
||||
|
||||
impl<'a, 'b> ComplGen<'a, 'b> {
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self {
|
||||
ComplGen { p: p }
|
||||
}
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self { ComplGen { p: p } }
|
||||
|
||||
pub fn generate<W: Write>(&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 +53,7 @@ pub fn all_subcommand_names(p: &Parser) -> Vec<String> {
|
|||
}
|
||||
|
||||
// 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,7 +73,9 @@ 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...");
|
||||
|
@ -86,7 +86,8 @@ 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);
|
||||
|
@ -94,16 +95,19 @@ 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);
|
||||
|
|
|
@ -12,9 +12,7 @@ pub struct PowerShellGen<'a, 'b>
|
|||
}
|
||||
|
||||
impl<'a, 'b> PowerShellGen<'a, 'b> {
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self {
|
||||
PowerShellGen { p: p }
|
||||
}
|
||||
pub fn new(p: &'b Parser<'a, 'b>) -> Self { PowerShellGen { p: p } }
|
||||
|
||||
pub fn generate_to<W: Write>(&self, buf: &mut W) {
|
||||
let bin_name = self.p.meta.bin_name.as_ref().unwrap();
|
||||
|
@ -32,7 +30,9 @@ 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#"
|
||||
|
@ -75,18 +75,17 @@ 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 {
|
||||
|
@ -103,10 +102,13 @@ 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);
|
||||
}
|
||||
|
|
|
@ -18,14 +18,7 @@ pub enum Shell {
|
|||
|
||||
impl Shell {
|
||||
/// A list of possible variants in `&'static str` form
|
||||
pub fn variants() -> [&'static str; 4] {
|
||||
[
|
||||
"zsh",
|
||||
"bash",
|
||||
"fish",
|
||||
"powershell"
|
||||
]
|
||||
}
|
||||
pub fn variants() -> [&'static str; 4] { ["zsh", "bash", "fish", "powershell"] }
|
||||
}
|
||||
|
||||
impl FromStr for Shell {
|
||||
|
@ -38,9 +31,7 @@ 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]")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,11 +39,10 @@ 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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,7 @@ 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<W: Write>(&self, buf: &mut W) {
|
||||
|
@ -72,11 +70,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
|
||||
|
@ -114,7 +112,7 @@ _{bin_name_underscore}_commands() {{
|
|||
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]'
|
||||
//
|
||||
|
@ -142,7 +140,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);
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +152,7 @@ fn subcommands_and_args_of(p: &Parser) -> String {
|
|||
let a = format!("\"{name}:{help}\" \\",
|
||||
name = arg.b.name.to_ascii_uppercase(),
|
||||
help = arg.b.help.unwrap_or(""));
|
||||
|
||||
|
||||
if !a.is_empty() {
|
||||
ret.push(a);
|
||||
}
|
||||
|
@ -184,7 +182,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"
|
||||
|
@ -239,7 +237,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)]
|
||||
|
@ -265,15 +263,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() {
|
||||
|
@ -299,12 +297,20 @@ 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()
|
||||
};
|
||||
|
@ -341,10 +347,18 @@ 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,
|
||||
|
@ -369,4 +383,4 @@ fn write_flags_of(p: &Parser) -> String {
|
|||
}
|
||||
|
||||
ret.join("\n")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
|
@ -402,9 +402,7 @@ impl Error {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn write_to<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||
write!(w, "{}", self.message)
|
||||
}
|
||||
pub fn write_to<W: Write>(&self, w: &mut W) -> io::Result<()> { write!(w, "{}", self.message) }
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn argument_conflict<'a, 'b, A, O, U>(arg: &A,
|
||||
|
@ -858,21 +856,15 @@ impl Error {
|
|||
}
|
||||
|
||||
impl StdError for Error {
|
||||
fn description(&self) -> &str {
|
||||
&*self.message
|
||||
}
|
||||
fn description(&self) -> &str { &*self.message }
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut std_fmt::Formatter) -> std_fmt::Result {
|
||||
writeln!(f, "{}", self.message)
|
||||
}
|
||||
fn fmt(&self, f: &mut std_fmt::Formatter) -> std_fmt::Result { writeln!(f, "{}", self.message) }
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Self {
|
||||
Error::with_description(e.description(), ErrorKind::Io)
|
||||
}
|
||||
fn from(e: io::Error) -> Self { Error::with_description(e.description(), ErrorKind::Io) }
|
||||
}
|
||||
|
||||
impl From<std_fmt::Error> for Error {
|
||||
|
|
|
@ -142,16 +142,12 @@ impl<T: fmt::Display> Format<T> {
|
|||
|
||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
impl<T: AsRef<str>> fmt::Display for Format<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", &self.format())
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", &self.format()) }
|
||||
}
|
||||
|
||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||
impl<T: fmt::Display> fmt::Display for Format<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", &self.format())
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", &self.format()) }
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "color", not(target_os = "windows")))]
|
||||
|
|
|
@ -28,19 +28,13 @@ impl OsStrExt3 for OsStr {
|
|||
use std::mem;
|
||||
unsafe { mem::transmute(b) }
|
||||
}
|
||||
fn as_bytes(&self) -> &[u8] {
|
||||
self.to_str().map(|s| s.as_bytes()).expect(INVALID_UTF8)
|
||||
}
|
||||
fn as_bytes(&self) -> &[u8] { self.to_str().map(|s| s.as_bytes()).expect(INVALID_UTF8) }
|
||||
}
|
||||
|
||||
impl OsStrExt2 for OsStr {
|
||||
fn starts_with(&self, s: &[u8]) -> bool {
|
||||
self.as_bytes().starts_with(s)
|
||||
}
|
||||
fn starts_with(&self, s: &[u8]) -> bool { self.as_bytes().starts_with(s) }
|
||||
|
||||
fn is_empty_(&self) -> bool {
|
||||
self.as_bytes().is_empty()
|
||||
}
|
||||
fn is_empty_(&self) -> bool { self.as_bytes().is_empty() }
|
||||
|
||||
fn contains_byte(&self, byte: u8) -> bool {
|
||||
for b in self.as_bytes() {
|
||||
|
@ -74,9 +68,7 @@ impl OsStrExt2 for OsStr {
|
|||
(OsStr::from_bytes(&self.as_bytes()[..i]), OsStr::from_bytes(&self.as_bytes()[i..]))
|
||||
}
|
||||
|
||||
fn len_(&self) -> usize {
|
||||
self.as_bytes().len()
|
||||
}
|
||||
fn len_(&self) -> usize { self.as_bytes().len() }
|
||||
|
||||
fn split(&self, b: u8) -> OsSplit {
|
||||
OsSplit {
|
||||
|
|
|
@ -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>) {
|
||||
|
@ -192,14 +192,10 @@ impl<'a> UsageParser<'a> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn name_end(b: u8) -> bool {
|
||||
b != b']' && b != b'>'
|
||||
}
|
||||
fn name_end(b: u8) -> bool { b != b']' && b != b'>' }
|
||||
|
||||
#[inline]
|
||||
fn token(b: u8) -> bool {
|
||||
b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'-'
|
||||
}
|
||||
fn token(b: u8) -> bool { b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'-' }
|
||||
|
||||
#[inline]
|
||||
fn long_end(b: u8) -> bool {
|
||||
|
@ -207,9 +203,7 @@ fn long_end(b: u8) -> bool {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn help_start(b: u8) -> bool {
|
||||
b != b'\''
|
||||
}
|
||||
fn help_start(b: u8) -> bool { b != b'\'' }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
@ -990,7 +984,8 @@ 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::<Vec<_>>(), [&"option"]);
|
||||
assert_eq!(d.val_names.unwrap().values().collect::<Vec<_>>(),
|
||||
[&"option"]);
|
||||
assert!(d.num_vals.is_none());
|
||||
}
|
||||
|
||||
|
@ -1199,7 +1194,8 @@ 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::<Vec<_>>(), [&"üñíčöĐ€"]);
|
||||
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(),
|
||||
[&"üñíčöĐ€"]);
|
||||
assert_eq!(a.help, Some("hælp"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue