mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Suppress warnings in generated code
This commit is contained in:
parent
54f2072a66
commit
bfc850e99a
3 changed files with 88 additions and 28 deletions
|
@ -16,6 +16,58 @@ use syn::{punctuated::Punctuated, spanned::Spanned, Token};
|
|||
|
||||
use super::{sub_type, Attrs, Kind, ParserKind, Ty};
|
||||
|
||||
pub fn gen_for_struct(
|
||||
struct_name: &syn::Ident,
|
||||
fields: &Punctuated<syn::Field, Token![,]>,
|
||||
parent_attribute: &Attrs,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let constructor = gen_constructor(fields, parent_attribute);
|
||||
|
||||
quote! {
|
||||
#[allow(dead_code, unreachable_code, unused_variables)]
|
||||
#[allow(
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::perf,
|
||||
clippy::deprecated,
|
||||
clippy::nursery,
|
||||
clippy::cargo
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::FromArgMatches for #struct_name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
#struct_name #constructor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gen_for_enum(name: &syn::Ident) -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
#[allow(dead_code, unreachable_code, unused_variables)]
|
||||
#[allow(
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::perf,
|
||||
clippy::deprecated,
|
||||
clippy::nursery,
|
||||
clippy::cargo
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::FromArgMatches for #name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
let (name, subcmd) = matches.subcommand();
|
||||
<#name as ::clap::Subcommand>::from_subcommand(name, subcmd)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gen_constructor(
|
||||
fields: &Punctuated<syn::Field, Token![,]>,
|
||||
parent_attribute: &Attrs,
|
||||
|
@ -155,31 +207,3 @@ pub fn gen_constructor(
|
|||
#( #fields ),*
|
||||
}}
|
||||
}
|
||||
|
||||
pub fn gen_for_struct(
|
||||
struct_name: &syn::Ident,
|
||||
fields: &Punctuated<syn::Field, Token![,]>,
|
||||
parent_attribute: &Attrs,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let constructor = gen_constructor(fields, parent_attribute);
|
||||
|
||||
quote! {
|
||||
impl ::clap::FromArgMatches for #struct_name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
#struct_name #constructor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gen_for_enum(name: &syn::Ident) -> proc_macro2::TokenStream {
|
||||
quote! {
|
||||
impl ::clap::FromArgMatches for #name {
|
||||
fn from_arg_matches(matches: &::clap::ArgMatches) -> Self {
|
||||
let (name, subcmd) = matches.subcommand();
|
||||
<#name as ::clap::Subcommand>::from_subcommand(name, subcmd)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,18 @@ pub fn gen_for_struct(
|
|||
let augment_clap = gen_augment_clap_fn(fields, &attrs);
|
||||
|
||||
let tokens = quote! {
|
||||
#[allow(dead_code, unreachable_code, unused_variables)]
|
||||
#[allow(
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::perf,
|
||||
clippy::deprecated,
|
||||
clippy::nursery,
|
||||
clippy::cargo
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::IntoApp for #struct_name {
|
||||
#into_app
|
||||
#augment_clap
|
||||
|
@ -47,6 +59,18 @@ pub fn gen_for_enum(name: &syn::Ident) -> TokenStream {
|
|||
let app_name = env::var("CARGO_PKG_NAME").ok().unwrap_or_default();
|
||||
|
||||
quote! {
|
||||
#[allow(dead_code, unreachable_code, unused_variables)]
|
||||
#[allow(
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::perf,
|
||||
clippy::deprecated,
|
||||
clippy::nursery,
|
||||
clippy::cargo
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::IntoApp for #name {
|
||||
fn into_app<'b>() -> ::clap::App<'b> {
|
||||
let app = ::clap::App::new(#app_name)
|
||||
|
|
|
@ -21,6 +21,18 @@ pub fn gen_for_enum(name: &Ident, attrs: &[Attribute], e: &DataEnum) -> TokenStr
|
|||
let augment_subcommands = gen_augment_subcommands(&e.variants, &attrs);
|
||||
|
||||
quote! {
|
||||
#[allow(dead_code, unreachable_code, unused_variables)]
|
||||
#[allow(
|
||||
clippy::style,
|
||||
clippy::complexity,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::perf,
|
||||
clippy::deprecated,
|
||||
clippy::nursery,
|
||||
clippy::cargo
|
||||
)]
|
||||
#[deny(clippy::correctness)]
|
||||
impl ::clap::Subcommand for #name {
|
||||
#augment_subcommands
|
||||
#from_subcommand
|
||||
|
|
Loading…
Add table
Reference in a new issue