mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
chore: removes warnings and commented out code
This commit is contained in:
parent
a769639f8b
commit
53a7d72523
9 changed files with 57 additions and 153 deletions
|
@ -10,7 +10,6 @@ use std::io::{self, BufRead, BufWriter, Write};
|
|||
use std::iter::Peekable;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use std::slice::Iter;
|
||||
|
||||
// Third Party
|
||||
#[cfg(feature = "yaml")]
|
||||
|
@ -1828,33 +1827,6 @@ impl<'a, 'b> App<'a, 'b> {
|
|||
args
|
||||
}
|
||||
|
||||
pub(crate) fn unroll_conflicts_for_group(&self, group: &'a str) -> Vec<&'a str> {
|
||||
let mut g_vec = vec![group];
|
||||
let mut confs = vec![];
|
||||
|
||||
while let Some(ref g) = g_vec.pop() {
|
||||
if let Some(ref c_vec) = self
|
||||
.groups
|
||||
.iter()
|
||||
.find(|grp| &grp.name == g)
|
||||
.expect(INTERNAL_ERROR_MSG)
|
||||
.conflicts
|
||||
{
|
||||
for c in c_vec {
|
||||
if !confs.contains(c) {
|
||||
if self.find(c).is_some() {
|
||||
confs.push(c)
|
||||
} else {
|
||||
g_vec.push(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
confs
|
||||
}
|
||||
|
||||
pub(crate) fn unroll_requirements_for_arg(
|
||||
&self,
|
||||
arg: &str,
|
||||
|
|
|
@ -29,17 +29,6 @@ fn str_width(s: &str) -> usize { UnicodeWidthStr::width(s) }
|
|||
|
||||
const TAB: &'static str = " ";
|
||||
|
||||
// trait ArgWithOrder<'b, 'c>: Display + DispOrder {
|
||||
// fn as_base(&self) -> &Arg<'b, 'c>;
|
||||
// }
|
||||
// impl<'b, 'c, T> ArgWithOrder<'b, 'c> for T
|
||||
// where
|
||||
// T: Display + DispOrder,
|
||||
// {
|
||||
// fn as_base(&self) -> &Arg<'b, 'c> { self }
|
||||
// }
|
||||
// fn as_arg_trait<'w, 'b, T: ArgWithOrder<'w, 'b>>(x: &T) -> &ArgWithOrder<'w, 'b> { x }
|
||||
|
||||
macro_rules! color {
|
||||
($_self:ident, $s:expr, $c:ident) => {
|
||||
if $_self.color {
|
||||
|
@ -783,7 +772,6 @@ impl<'w> Help<'w> {
|
|||
for sc in subcommands!(app).filter(|s| !s.is_set(AppSettings::Hidden)) {
|
||||
let btm = ord_m.entry(sc.disp_ord).or_insert(BTreeMap::new());
|
||||
self.longest = cmp::max(self.longest, str_width(sc.name.as_str()));
|
||||
//self.longest = cmp::max(self.longest, sc.p.meta.name.len());
|
||||
btm.insert(sc.name.clone(), sc.clone());
|
||||
}
|
||||
|
||||
|
|
|
@ -110,20 +110,12 @@ impl<'a> ArgMatcher<'a> {
|
|||
self.insert(arg);
|
||||
}
|
||||
|
||||
pub fn inc_occurrences_of(&mut self, args: &[&'a str]) {
|
||||
debugln!("ArgMatcher::inc_occurrences_of: args={:?}", args);
|
||||
for arg in args {
|
||||
self.inc_occurrence_of(arg);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_val_to(&mut self, arg: &'a str, val: &OsStr) {
|
||||
let ma = self.entry(arg).or_insert(MatchedArg {
|
||||
occurs: 0,
|
||||
indices: Vec::with_capacity(1),
|
||||
vals: Vec::with_capacity(1),
|
||||
});
|
||||
// let len = ma.vals.len() + 1;
|
||||
ma.vals.push(val.to_owned());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ use std::mem;
|
|||
)
|
||||
)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::slice::Iter;
|
||||
|
||||
// Third party facade
|
||||
use util::VecMap;
|
||||
|
@ -26,7 +25,7 @@ use util::VecMap;
|
|||
// Internal
|
||||
use build::app::Propagation;
|
||||
use build::AppSettings as AS;
|
||||
use build::{App, Arg, ArgGroup, ArgSettings};
|
||||
use build::{App, Arg, ArgSettings};
|
||||
use output::Help;
|
||||
use output::Usage;
|
||||
use parse::errors::Error as ClapError;
|
||||
|
@ -88,10 +87,8 @@ fn count_arg<'a, 'b>(
|
|||
positionals.insert(i, a.name);
|
||||
} else if a.is_set(ArgSettings::TakesValue) {
|
||||
*num_opts += 1;
|
||||
// a.unified_ord = *num_flags + *num_opts;
|
||||
} else {
|
||||
*num_flags += 1;
|
||||
// a.unified_ord = *num_flags + *num_opts;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,13 +307,6 @@ where
|
|||
debugln!("Parser::_build;");
|
||||
|
||||
for a in &mut self.app.args {
|
||||
// Add conditional requirements
|
||||
// if let Some(ref r_ifs) = a.r_ifs {
|
||||
// for &(arg, val) in r_ifs {
|
||||
// self.r_ifs.push((arg, val, a.name));
|
||||
// }
|
||||
// }
|
||||
|
||||
// Add args with default requirements
|
||||
if a.is_set(ArgSettings::Required) {
|
||||
debugln!("Parser::_build: adding {} to default requires", a.name);
|
||||
|
@ -969,34 +959,6 @@ where
|
|||
|| subcommands!(self.app).any(|s| s.long_about.is_some())
|
||||
}
|
||||
|
||||
// fn _help(&self, mut use_long: bool) -> ClapError {
|
||||
// debugln!("Parser::_help: use_long={:?}", use_long && self.use_long_help());
|
||||
// use_long = use_long && self.use_long_help();
|
||||
// let mut buf = vec![];
|
||||
// match Help::write_parser_help(&mut buf, self, use_long) {
|
||||
// Err(e) => e,
|
||||
// _ => ClapError {
|
||||
// message: String::from_utf8(buf).unwrap_or_default(),
|
||||
// kind: ErrorKind::HelpDisplayed,
|
||||
// info: None,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fn _version(&self, use_long: bool) -> ClapError {
|
||||
// debugln!("Parser::_version: ");
|
||||
// let out = io::stdout();
|
||||
// let mut buf_w = BufWriter::new(out.lock());
|
||||
// match self.print_version(&mut buf_w, use_long) {
|
||||
// Err(e) => e,
|
||||
// _ => ClapError {
|
||||
// message: String::new(),
|
||||
// kind: ErrorKind::VersionDisplayed,
|
||||
// info: None,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
fn parse_long_arg(
|
||||
&mut self,
|
||||
matcher: &mut ArgMatcher<'a>,
|
||||
|
@ -1530,7 +1492,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
// let used_arg = format!("--{}", arg);
|
||||
let used: Vec<&str> = matcher
|
||||
.arg_names()
|
||||
.filter(|ref n| {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// std
|
||||
#[allow(unused_imports)]
|
||||
use std::ascii::AsciiExt;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
// Internal
|
||||
use build::app::AppSettings as AS;
|
||||
|
@ -173,7 +172,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
fn build_conflict_err(&self, name: &str, matcher: &ArgMatcher<'a>) -> ClapResult<()> {
|
||||
debugln!("build_err!: name={}", name);
|
||||
let usg = Usage::new(self.p).create_usage_with_title(&[]);
|
||||
if let Some(a) = self.p.app.find(name) {
|
||||
if self.p.app.find(name).is_some() {
|
||||
for k in matcher.arg_names() {
|
||||
if let Some(a) = self.p.app.find(k) {
|
||||
if let Some(ref v) = a.blacklist {
|
||||
|
@ -351,10 +350,10 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
ma.vals
|
||||
);
|
||||
if let Some(arg) = self.p.app.find(name) {
|
||||
self.validate_arg_num_vals(arg, ma, matcher)?;
|
||||
self.validate_arg_num_vals(arg, ma)?;
|
||||
self.validate_arg_values(arg, ma, matcher)?;
|
||||
self.validate_arg_requires(arg, ma, matcher)?;
|
||||
self.validate_arg_num_occurs(arg, ma, matcher)?;
|
||||
self.validate_arg_num_occurs(arg, ma)?;
|
||||
} else {
|
||||
let grp = self
|
||||
.p
|
||||
|
@ -373,12 +372,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_arg_num_occurs(
|
||||
&self,
|
||||
a: &Arg,
|
||||
ma: &MatchedArg,
|
||||
matcher: &ArgMatcher<'a>,
|
||||
) -> ClapResult<()> {
|
||||
fn validate_arg_num_occurs(&self, a: &Arg, ma: &MatchedArg) -> ClapResult<()> {
|
||||
debugln!("Validator::validate_arg_num_occurs: a={};", a.name);
|
||||
if ma.occurs > 1 && !a.is_set(ArgSettings::MultipleOccurrences) {
|
||||
// Not the first time, and we don't allow multiples
|
||||
|
@ -391,12 +385,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_arg_num_vals(
|
||||
&self,
|
||||
a: &Arg,
|
||||
ma: &MatchedArg,
|
||||
matcher: &ArgMatcher<'a>,
|
||||
) -> ClapResult<()> {
|
||||
fn validate_arg_num_vals(&self, a: &Arg, ma: &MatchedArg) -> ClapResult<()> {
|
||||
debugln!("Validator::validate_arg_num_vals;");
|
||||
if let Some(num) = a.num_vals {
|
||||
debugln!("Validator::validate_arg_num_vals: num_vals set...{}", num);
|
||||
|
@ -593,18 +582,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
($how:ident, $_self:expr, $a:ident, $m:ident) => {{
|
||||
$a.r_unless
|
||||
.as_ref()
|
||||
.map(|ru| {
|
||||
!ru.iter().$how(|n| {
|
||||
$m.contains(n)
|
||||
// || {
|
||||
// if let Some(grp) = $_self.app.groups.iter().find(|g| &g.name == n) {
|
||||
// grp.args.iter().any(|arg| $m.contains(arg))
|
||||
// } else {
|
||||
// false
|
||||
// }
|
||||
// }
|
||||
})
|
||||
})
|
||||
.map(|ru| !ru.iter().$how(|n| $m.contains(n)))
|
||||
.unwrap_or(false)
|
||||
}};
|
||||
}
|
||||
|
@ -632,7 +610,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
|||
"Validator::missing_required_error: reqs={:?}",
|
||||
self.p.required
|
||||
);
|
||||
let mut usg = Usage::new(self.p);
|
||||
let usg = Usage::new(self.p);
|
||||
let req_args = if let Some(x) = incl {
|
||||
usg.get_required_usage_from(&[x], Some(matcher), true)
|
||||
.iter()
|
||||
|
|
|
@ -31,7 +31,7 @@ where
|
|||
self.0
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(i, e)| e.id == req)
|
||||
.find(|(_, e)| e.id == req)
|
||||
.map(|(i, _)| i)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -705,11 +705,9 @@ fn compare(left: &str, right: &str) -> bool {
|
|||
let re = Regex::new(" ").unwrap();
|
||||
println!("");
|
||||
println!("--> left");
|
||||
// println!("{}", left);
|
||||
println!("{}", re.replace_all(left, "\u{2022}"));
|
||||
println!("--> right");
|
||||
println!("{}", re.replace_all(right, "\u{2022}"));
|
||||
// println!("{}", right);
|
||||
println!("--")
|
||||
}
|
||||
b
|
||||
|
@ -721,45 +719,63 @@ fn build_app_with_name(s: &'static str) -> App<'static, 'static> {
|
|||
App::new(s)
|
||||
.about("Tests completions")
|
||||
.arg(Arg::with_name("file").help("some input file"))
|
||||
.subcommand(SubCommand::with_name("test")
|
||||
.about("tests things")
|
||||
.arg(Arg::with_name("case")
|
||||
.long("case")
|
||||
.takes_value(true)
|
||||
.help("the case to test")))
|
||||
.subcommand(
|
||||
SubCommand::with_name("test").about("tests things").arg(
|
||||
Arg::with_name("case")
|
||||
.long("case")
|
||||
.takes_value(true)
|
||||
.help("the case to test"),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn build_app_special_commands() -> App<'static, 'static> {
|
||||
build_app_with_name("my_app")
|
||||
.subcommand(SubCommand::with_name("some_cmd")
|
||||
.about("tests other things")
|
||||
.arg(Arg::with_name("config")
|
||||
.long("--config")
|
||||
.takes_value(true)
|
||||
.help("the other case to test")))
|
||||
.subcommand(
|
||||
SubCommand::with_name("some_cmd")
|
||||
.about("tests other things")
|
||||
.arg(
|
||||
Arg::with_name("config")
|
||||
.long("--config")
|
||||
.takes_value(true)
|
||||
.help("the other case to test"),
|
||||
),
|
||||
)
|
||||
.subcommand(SubCommand::with_name("some-cmd-with-hypens"))
|
||||
}
|
||||
|
||||
fn build_app_special_help() -> App<'static, 'static> {
|
||||
App::new("my_app")
|
||||
.arg(Arg::with_name("single-quotes")
|
||||
.long("single-quotes")
|
||||
.help("Can be 'always', 'auto', or 'never'"))
|
||||
.arg(Arg::with_name("double-quotes")
|
||||
.long("double-quotes")
|
||||
.help("Can be \"always\", \"auto\", or \"never\""))
|
||||
.arg(Arg::with_name("backticks")
|
||||
.long("backticks")
|
||||
.help("For more information see `echo test`"))
|
||||
.arg(Arg::with_name("backslash")
|
||||
.long("backslash")
|
||||
.help("Avoid '\\n'"))
|
||||
.arg(Arg::with_name("brackets")
|
||||
.long("brackets")
|
||||
.help("List packages [filter]"))
|
||||
.arg(Arg::with_name("expansions")
|
||||
.long("expansions")
|
||||
.help("Execute the shell command with $SHELL"))
|
||||
.arg(
|
||||
Arg::with_name("single-quotes")
|
||||
.long("single-quotes")
|
||||
.help("Can be 'always', 'auto', or 'never'"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("double-quotes")
|
||||
.long("double-quotes")
|
||||
.help("Can be \"always\", \"auto\", or \"never\""),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("backticks")
|
||||
.long("backticks")
|
||||
.help("For more information see `echo test`"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("backslash")
|
||||
.long("backslash")
|
||||
.help("Avoid '\\n'"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("brackets")
|
||||
.long("brackets")
|
||||
.help("List packages [filter]"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("expansions")
|
||||
.long("expansions")
|
||||
.help("Execute the shell command with $SHELL"),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -220,7 +220,6 @@ fn default_if_arg_present_with_value_no_default_fail() {
|
|||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
assert!(!m.is_present("arg"));
|
||||
//assert_eq!(m.value_of("arg").unwrap(), "default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -482,7 +482,6 @@ fn requires_if_present_mult_pass() {
|
|||
.get_matches_from_safe(vec!["unlessone", "--config=some.cfg"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -596,7 +595,6 @@ fn required_ifs_val_present_pass() {
|
|||
.get_matches_from_safe(vec!["ri", "--option", "spec", "--config", "my.cfg"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue