From 0af8a4aca794568f7e33f3a5d03f138ccf20bb46 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Fri, 2 Jun 2023 22:10:37 +0200 Subject: [PATCH] refactor: addressed compiler warnings --- examples/advanced_struct.rs | 6 +++--- examples/common.rs | 6 ------ examples/simple_enum.rs | 1 + examples/struct_with_context.rs | 10 +++++++-- examples/to_cli_args.rs | 21 +++++++++++-------- .../src/derives/interactive_clap/mod.rs | 10 ++++----- .../src/derives/to_cli_args/mod.rs | 10 ++++----- 7 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 examples/common.rs diff --git a/examples/advanced_struct.rs b/examples/advanced_struct.rs index d7c427d..1e021d4 100644 --- a/examples/advanced_struct.rs +++ b/examples/advanced_struct.rs @@ -40,7 +40,7 @@ impl interactive_clap::FromCli for Args { Err(err) => return ResultFromCli::Err(Some(clap_variant), err), }; } - let age = clap_variant.age; + let _age = clap_variant.age; if clap_variant.first_name.is_none() { clap_variant.first_name = match Self::input_first_name(&context) { Ok(Some(first_name)) => Some(first_name), @@ -48,7 +48,7 @@ impl interactive_clap::FromCli for Args { Err(err) => return ResultFromCli::Err(Some(clap_variant), err), }; } - let first_name = clap_variant.first_name.clone().expect("Unexpected error"); + let _first_name = clap_variant.first_name.clone().expect("Unexpected error"); if clap_variant.second_name.is_none() { clap_variant.second_name = match Self::input_second_name(&context) { Ok(Some(second_name)) => Some(second_name), @@ -56,7 +56,7 @@ impl interactive_clap::FromCli for Args { Err(err) => return ResultFromCli::Err(Some(clap_variant), err), }; } - let second_name = clap_variant.second_name.clone().expect("Unexpected error"); + let _second_name = clap_variant.second_name.clone().expect("Unexpected error"); ResultFromCli::Ok(clap_variant) } } diff --git a/examples/common.rs b/examples/common.rs deleted file mode 100644 index 308ba45..0000000 --- a/examples/common.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[derive(Debug, Clone)] -pub enum ConnectionConfig { - Testnet, - Mainnet, - Betanet, -} diff --git a/examples/simple_enum.rs b/examples/simple_enum.rs index f9b6c9c..5d42664 100644 --- a/examples/simple_enum.rs +++ b/examples/simple_enum.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] //This example shows how to parse data from the command line to an enum using the "interactive-clap" macro. // 1) build an example: cargo build --example simple_enum diff --git a/examples/struct_with_context.rs b/examples/struct_with_context.rs index 3ffd053..6b4ae17 100644 --- a/examples/struct_with_context.rs +++ b/examples/struct_with_context.rs @@ -8,9 +8,15 @@ use interactive_clap::{ResultFromCli, ToCliArgs}; -mod common; mod simple_enum; +#[derive(Debug, Clone)] +pub enum ConnectionConfig { + Testnet, + Mainnet, + Betanet, +} + #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = ())] #[interactive_clap(output_context = OfflineArgsContext)] @@ -60,7 +66,7 @@ impl From for () { #[derive(Debug)] pub struct NetworkContext { - pub connection_config: Option, + pub connection_config: Option, } #[derive(Debug, Clone, interactive_clap::InteractiveClap)] diff --git a/examples/to_cli_args.rs b/examples/to_cli_args.rs index 4387756..f57131c 100644 --- a/examples/to_cli_args.rs +++ b/examples/to_cli_args.rs @@ -11,10 +11,15 @@ use inquire::Select; use interactive_clap::{ResultFromCli, SelectVariantOrBack, ToCliArgs}; use strum::{EnumDiscriminants, EnumIter, EnumMessage, IntoEnumIterator}; -mod common; +#[derive(Debug, Clone)] +pub enum ConnectionConfig { + Testnet, + Mainnet, + Betanet, +} #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(context = common::ConnectionConfig)] +#[interactive_clap(context = ConnectionConfig)] struct OnlineArgs { /// What is the name of the network #[interactive_clap(skip_default_input_arg)] @@ -24,9 +29,7 @@ struct OnlineArgs { } impl OnlineArgs { - fn input_network_name( - _context: &common::ConnectionConfig, - ) -> color_eyre::eyre::Result> { + fn input_network_name(_context: &ConnectionConfig) -> color_eyre::eyre::Result> { match inquire::Text::new("Input network name").prompt() { Ok(value) => Ok(Some(value)), Err( @@ -65,7 +68,7 @@ impl From for CliSubmit { } impl interactive_clap::FromCli for Submit { - type FromCliContext = common::ConnectionConfig; + type FromCliContext = ConnectionConfig; type FromCliError = color_eyre::eyre::Error; fn from_cli( @@ -101,7 +104,7 @@ impl interactive_clap::ToCliArgs for CliSubmit { impl Submit { fn choose_variant( - context: common::ConnectionConfig, + context: ConnectionConfig, ) -> ResultFromCli< ::CliVariant, ::FromCliError, @@ -160,7 +163,7 @@ impl std::fmt::Display for SubmitDiscriminants { } #[derive(Debug, Clone, interactive_clap::InteractiveClap, clap::Args)] -#[interactive_clap(context = common::ConnectionConfig)] +#[interactive_clap(context = ConnectionConfig)] pub struct Args { age: u64, first_name: String, @@ -169,7 +172,7 @@ pub struct Args { fn main() -> color_eyre::Result<()> { let mut cli_online_args = OnlineArgs::parse(); - let context = common::ConnectionConfig::Testnet; //#[interactive_clap(context = common::ConnectionConfig)] + let context = ConnectionConfig::Testnet; //#[interactive_clap(context = ConnectionConfig)] let cli_args = loop { match ::from_cli( Some(cli_online_args), diff --git a/interactive-clap-derive/src/derives/interactive_clap/mod.rs b/interactive-clap-derive/src/derives/interactive_clap/mod.rs index ec053e6..0dae9d3 100644 --- a/interactive-clap-derive/src/derives/interactive_clap/mod.rs +++ b/interactive-clap-derive/src/derives/interactive_clap/mod.rs @@ -171,7 +171,7 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { quote! () }; - let gen = quote! { + quote! { #[derive(Debug, Default, Clone, clap::Parser, interactive_clap::ToCliArgs)] #[clap(author, version, about, long_about = None)] pub struct #cli_name { @@ -207,8 +207,7 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { } #clap_enum_for_named_arg - }; - gen.into() + } } syn::Data::Enum(syn::DataEnum { variants, .. }) => { let enum_variants = variants.iter().map(|variant| { @@ -300,7 +299,7 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { let fn_from_cli_for_enum = self::methods::from_cli_for_enum::from_cli_for_enum(ast, variants); - let gen = quote! { + quote! { #[derive(Debug, Clone, clap::Parser, interactive_clap::ToCliArgs)] pub enum #cli_name { #( #enum_variants, )* @@ -333,8 +332,7 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream { <#cli_name as clap::Parser>::parse() } } - }; - gen.into() + } } _ => abort_call_site!("`#[derive(InteractiveClap)]` only supports structs and enums"), } diff --git a/interactive-clap-derive/src/derives/to_cli_args/mod.rs b/interactive-clap-derive/src/derives/to_cli_args/mod.rs index b960d7a..f6ed902 100644 --- a/interactive-clap-derive/src/derives/to_cli_args/mod.rs +++ b/interactive-clap-derive/src/derives/to_cli_args/mod.rs @@ -39,7 +39,7 @@ pub fn impl_to_cli_args(ast: &syn::DeriveInput) -> TokenStream { } let args_push_front_vec = args_push_front_vec.into_iter().rev(); - let gen = quote! { + quote! { impl interactive_clap::ToCliArgs for #cli_name { fn to_cli_args(&self) -> std::collections::VecDeque { #args_subcommand; @@ -47,8 +47,7 @@ pub fn impl_to_cli_args(ast: &syn::DeriveInput) -> TokenStream { args } } - }; - gen.into() + } } syn::Data::Enum(syn::DataEnum { variants, .. }) => { let enum_variants = variants.iter().map(|variant| { @@ -81,7 +80,7 @@ pub fn impl_to_cli_args(ast: &syn::DeriveInput) -> TokenStream { ), } }); - let gen = quote! { + quote! { impl interactive_clap::ToCliArgs for #cli_name { fn to_cli_args(&self) -> std::collections::VecDeque { match self { @@ -89,8 +88,7 @@ pub fn impl_to_cli_args(ast: &syn::DeriveInput) -> TokenStream { } } } - }; - gen.into() + } } _ => abort_call_site!("`#[derive(InteractiveClap)]` only supports structs and enums"), }