mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Fix some nightly clippy warnings
This commit is contained in:
parent
947523f7f5
commit
c4f534228b
15 changed files with 37 additions and 43 deletions
|
@ -152,7 +152,7 @@ fn gen_parsers(
|
|||
Ty::Option => {
|
||||
if attrs.is_enum() {
|
||||
if let Some(subty) = subty_if_name(&field.ty, "Option") {
|
||||
parse = gen_arg_enum_parse(subty, &attrs);
|
||||
parse = gen_arg_enum_parse(subty, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ fn gen_parsers(
|
|||
Ty::Vec => {
|
||||
if attrs.is_enum() {
|
||||
if let Some(subty) = subty_if_name(&field.ty, "Vec") {
|
||||
parse = gen_arg_enum_parse(subty, &attrs);
|
||||
parse = gen_arg_enum_parse(subty, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ fn gen_parsers(
|
|||
|
||||
Ty::Other => {
|
||||
if attrs.is_enum() {
|
||||
parse = gen_arg_enum_parse(&field.ty, &attrs);
|
||||
parse = gen_arg_enum_parse(&field.ty, attrs);
|
||||
}
|
||||
|
||||
quote_spanned! { ty.span()=>
|
||||
|
|
|
@ -179,7 +179,7 @@ pub fn gen_app_augmentation(
|
|||
) -> TokenStream {
|
||||
let mut subcmds = fields.iter().filter_map(|field| {
|
||||
let attrs = Attrs::from_field(
|
||||
&field,
|
||||
field,
|
||||
parent_attribute.casing(),
|
||||
parent_attribute.env_casing(),
|
||||
);
|
||||
|
|
|
@ -236,7 +236,7 @@ fn gen_from_subcommand(
|
|||
let sub_name = attrs.cased_name();
|
||||
let variant_name = &variant.ident;
|
||||
let constructor_block = match variant.fields {
|
||||
Named(ref fields) => from_arg_matches::gen_constructor(&fields.named, &attrs),
|
||||
Named(ref fields) => from_arg_matches::gen_constructor(&fields.named, attrs),
|
||||
Unit => quote!(),
|
||||
Unnamed(ref fields) if fields.unnamed.len() == 1 => {
|
||||
let ty = &fields.unnamed[0];
|
||||
|
|
|
@ -61,7 +61,7 @@ pub trait Generator {
|
|||
fn all_subcommands(app: &App) -> Vec<(String, String)> {
|
||||
let mut subcmds: Vec<_> = Self::subcommands(app);
|
||||
|
||||
for sc_v in app.get_subcommands().map(|s| Self::all_subcommands(&s)) {
|
||||
for sc_v in app.get_subcommands().map(|s| Self::all_subcommands(s)) {
|
||||
subcmds.extend(sc_v);
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ fn option_details_for_path(app: &App, path: &str) -> String {
|
|||
fn vals_for(o: &Arg) -> String {
|
||||
debug!("vals_for: o={}", o.get_name());
|
||||
|
||||
if let Some(ref vals) = o.get_possible_values() {
|
||||
if let Some(vals) = o.get_possible_values() {
|
||||
format!("$(compgen -W \"{}\" -- \"${{cur}}\")", vals.join(" "))
|
||||
} else {
|
||||
String::from("$(compgen -f \"${cur}\")")
|
||||
|
|
|
@ -132,7 +132,7 @@ fn generate_inner<'help>(
|
|||
);
|
||||
|
||||
for subcommand in p.get_subcommands() {
|
||||
let subcommand_subcommands_cases = generate_inner(&subcommand, &command_name, names);
|
||||
let subcommand_subcommands_cases = generate_inner(subcommand, &command_name, names);
|
||||
subcommands_cases.push_str(&subcommand_subcommands_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ fn gen_fish_inner(root_command: &str, app: &App, buffer: &mut String) {
|
|||
basic_template.push_str(" -n \"__fish_use_subcommand\"");
|
||||
}
|
||||
} else {
|
||||
bin_name = &app.get_name();
|
||||
bin_name = app.get_name();
|
||||
basic_template
|
||||
.push_str(format!(" -n \"__fish_seen_subcommand_from {}\"", bin_name).as_str());
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ fn value_completion(option: &Arg) -> String {
|
|||
return "".to_string();
|
||||
}
|
||||
|
||||
if let Some(ref data) = option.get_possible_values() {
|
||||
if let Some(data) = option.get_possible_values() {
|
||||
format!(" -r -f -a \"{}\"", data.join(" "))
|
||||
} else {
|
||||
// NB! If you change this, please also update the table in `ValueHint` documentation.
|
||||
|
|
|
@ -63,7 +63,7 @@ fn escape_string(string: &str) -> String {
|
|||
|
||||
fn get_tooltip<T: ToString>(help: Option<&str>, data: T) -> String {
|
||||
match help {
|
||||
Some(help) => escape_string(&help),
|
||||
Some(help) => escape_string(help),
|
||||
_ => data.to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ fn generate_inner<'help>(
|
|||
);
|
||||
|
||||
for subcommand in p.get_subcommands() {
|
||||
let subcommand_subcommands_cases = generate_inner(&subcommand, &command_name, names);
|
||||
let subcommand_subcommands_cases = generate_inner(subcommand, &command_name, names);
|
||||
subcommands_cases.push_str(&subcommand_subcommands_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ fn subcommands_of(p: &App) -> String {
|
|||
for command in p.get_subcommands() {
|
||||
debug!("subcommands_of:iter: subcommand={}", command.get_name());
|
||||
|
||||
add_subcommands(command, &command.get_name(), &mut segments);
|
||||
add_subcommands(command, command.get_name(), &mut segments);
|
||||
|
||||
for alias in command.get_visible_aliases() {
|
||||
add_subcommands(command, alias, &mut segments);
|
||||
|
|
|
@ -70,7 +70,7 @@ pub(crate) fn assert_app(app: &App) {
|
|||
}
|
||||
|
||||
for (short_alias, _) in &arg.short_aliases {
|
||||
short_flags.push(Flag::Arg(format!("-{}", short_alias), &arg.name));
|
||||
short_flags.push(Flag::Arg(format!("-{}", short_alias), arg.name));
|
||||
}
|
||||
|
||||
if let Some(l) = arg.long.as_ref() {
|
||||
|
@ -78,7 +78,7 @@ pub(crate) fn assert_app(app: &App) {
|
|||
}
|
||||
|
||||
for (long_alias, _) in &arg.aliases {
|
||||
long_flags.push(Flag::Arg(format!("--{}", long_alias), &arg.name));
|
||||
long_flags.push(Flag::Arg(format!("--{}", long_alias), arg.name));
|
||||
}
|
||||
|
||||
// Name conflicts
|
||||
|
|
|
@ -125,7 +125,7 @@ impl<'help> Arg<'help> {
|
|||
/// Get the name of the argument
|
||||
#[inline]
|
||||
pub fn get_name(&self) -> &str {
|
||||
&self.name
|
||||
self.name
|
||||
}
|
||||
|
||||
/// Get the help specified for this argument, if any
|
||||
|
@ -4880,7 +4880,7 @@ impl<'help> PartialOrd for Arg<'help> {
|
|||
|
||||
impl<'help> Ord for Arg<'help> {
|
||||
fn cmp(&self, other: &Arg) -> Ordering {
|
||||
self.name.cmp(&other.name)
|
||||
self.name.cmp(other.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -874,7 +874,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
|
|||
self.warning(self.parser.app.subcommand_header.unwrap_or("SUBCOMMANDS"))?;
|
||||
self.warning(":\n")?;
|
||||
|
||||
self.write_subcommands(&self.parser.app)?;
|
||||
self.write_subcommands(self.parser.app)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -149,21 +149,15 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
|||
let placeholder = self.p.app.subcommand_placeholder.unwrap_or("SUBCOMMAND");
|
||||
if self.p.is_set(AS::SubcommandsNegateReqs) || self.p.is_set(AS::ArgsNegateSubcommands)
|
||||
{
|
||||
usage.push_str("\n ");
|
||||
if !self.p.is_set(AS::ArgsNegateSubcommands) {
|
||||
usage.push_str("\n ");
|
||||
usage.push_str(&*self.create_help_usage(false));
|
||||
|
||||
usage.push_str(" <");
|
||||
usage.push_str(placeholder);
|
||||
usage.push('>');
|
||||
} else {
|
||||
usage.push_str("\n ");
|
||||
usage.push_str(&*name);
|
||||
|
||||
usage.push_str(" <");
|
||||
usage.push_str(placeholder);
|
||||
usage.push('>');
|
||||
}
|
||||
usage.push_str(" <");
|
||||
usage.push_str(placeholder);
|
||||
usage.push('>');
|
||||
} else if self.p.is_set(AS::SubcommandRequired)
|
||||
|| self.p.is_set(AS::SubcommandRequiredElseHelp)
|
||||
{
|
||||
|
@ -384,7 +378,7 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
|||
let mut unrolled_reqs = vec![];
|
||||
|
||||
for a in self.p.required.iter() {
|
||||
if let Some(ref m) = matcher {
|
||||
if let Some(m) = matcher {
|
||||
for aa in self.p.app.unroll_requirements_for_arg(a, m) {
|
||||
unrolled_reqs.push(aa);
|
||||
}
|
||||
|
@ -417,7 +411,7 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
|||
.filter(|name| !(matcher.is_some() && matcher.as_ref().unwrap().contains(name)))
|
||||
{
|
||||
debug!("Usage::get_required_usage_from:iter:{:?}", a);
|
||||
let arg = self.p.app.find(&a).expect(INTERNAL_ERROR_MSG).to_string();
|
||||
let arg = self.p.app.find(a).expect(INTERNAL_ERROR_MSG).to_string();
|
||||
ret_val.push(arg);
|
||||
}
|
||||
let mut g_vec: Vec<String> = vec![];
|
||||
|
@ -430,9 +424,9 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
|||
let have_group_entry = self
|
||||
.p
|
||||
.app
|
||||
.unroll_args_in_group(&g)
|
||||
.unroll_args_in_group(g)
|
||||
.iter()
|
||||
.any(|arg| m.contains(&arg));
|
||||
.any(|arg| m.contains(arg));
|
||||
if have_group_entry {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -203,10 +203,11 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
);
|
||||
}
|
||||
|
||||
let mut found = false;
|
||||
|
||||
if self.is_set(AS::AllowMissingPositional) {
|
||||
// Check that if a required positional argument is found, all positions with a lower
|
||||
// index are also required.
|
||||
let mut found = false;
|
||||
let mut foundx2 = false;
|
||||
|
||||
for p in self.app.get_positionals() {
|
||||
|
@ -239,7 +240,6 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
} else {
|
||||
// Check that if a required positional argument is found, all positions with a lower
|
||||
// index are also required
|
||||
let mut found = false;
|
||||
for p in (1..=num_p).rev().filter_map(|n| self.app.args.get(&n)) {
|
||||
if found {
|
||||
assert!(
|
||||
|
@ -632,7 +632,7 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
// If argument follows a `--`
|
||||
if self.is_set(AS::TrailingValues) {
|
||||
// If the arg matches a subcommand name, or any of its aliases (if defined)
|
||||
if self.possible_subcommand(&arg_os).is_some() {
|
||||
if self.possible_subcommand(arg_os).is_some() {
|
||||
return ClapError::unnecessary_double_dash(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
Usage::new(self).create_usage_with_title(&[]),
|
||||
|
@ -1466,7 +1466,7 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
// remove future overrides in reverse seen order
|
||||
for arg in self.seen.iter().rev() {
|
||||
for (a, overr) in arg_overrides.iter().filter(|(a, _)| a == arg) {
|
||||
if !to_rem.contains(&a) {
|
||||
if !to_rem.contains(a) {
|
||||
to_rem.push((*overr).clone());
|
||||
}
|
||||
}
|
||||
|
@ -1508,7 +1508,7 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
debug!("Parser::add_value: has conditional defaults");
|
||||
if matcher.get(&arg.id).is_none() {
|
||||
for (id, val, default) in arg.default_vals_ifs.values() {
|
||||
let add = if let Some(a) = matcher.get(&id) {
|
||||
let add = if let Some(a) = matcher.get(id) {
|
||||
if let Some(v) = val {
|
||||
a.vals_flatten().any(|value| v == value)
|
||||
} else {
|
||||
|
@ -1644,7 +1644,7 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
let did_you_mean = suggestions::did_you_mean_flag(
|
||||
arg,
|
||||
remaining_args,
|
||||
longs.iter().map(|ref x| &x[..]),
|
||||
longs.iter().map(|x| &x[..]),
|
||||
self.app.subcommands.as_mut_slice(),
|
||||
);
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
.filter_map(|k| {
|
||||
let arg = self.p.app.find(k);
|
||||
// For an arg that blacklists `name`, this will return `Some((k, a))` to indicate a conflict.
|
||||
arg.filter(|a| a.blacklist.contains(&name)).map(|a| (k, a))
|
||||
arg.filter(|a| a.blacklist.contains(name)).map(|a| (k, a))
|
||||
})
|
||||
.try_for_each(|(k, a)| {
|
||||
// The error will be then constructed according to the first conflict.
|
||||
|
@ -358,7 +358,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
// Now we need to know which groups this arg was a member of, to add all other
|
||||
// args in that group to the conflicts, as well as any args those args conflict
|
||||
// with
|
||||
for grp in self.p.app.groups_for_arg(&name) {
|
||||
for grp in self.p.app.groups_for_arg(name) {
|
||||
if let Some(g) = self
|
||||
.p
|
||||
.app
|
||||
|
@ -532,11 +532,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
debug!("Validator::validate_arg_requires:{:?}", a.name);
|
||||
for (val, name) in &a.requires {
|
||||
if let Some(val) = val {
|
||||
let missing_req = |v| v == val && !matcher.contains(&name);
|
||||
let missing_req = |v| v == val && !matcher.contains(name);
|
||||
if ma.vals_flatten().any(missing_req) {
|
||||
return self.missing_required_error(matcher, vec![a.id.clone()]);
|
||||
}
|
||||
} else if !matcher.contains(&name) {
|
||||
} else if !matcher.contains(name) {
|
||||
return self.missing_required_error(matcher, vec![name.clone()]);
|
||||
}
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
|
||||
for arg_or_group in self.p.required.iter().filter(|r| !matcher.contains(r)) {
|
||||
debug!("Validator::validate_required:iter:aog={:?}", arg_or_group);
|
||||
if let Some(arg) = self.p.app.find(&arg_or_group) {
|
||||
if let Some(arg) = self.p.app.find(arg_or_group) {
|
||||
debug!("Validator::validate_required:iter: This is an arg");
|
||||
if !self.is_missing_required_ok(arg, matcher) {
|
||||
return self.missing_required_error(matcher, vec![]);
|
||||
|
|
Loading…
Reference in a new issue