mirror of
https://github.com/Drop-OSS/interactive-clap.git
synced 2026-01-30 20:55:25 +01:00
refactor: addressed compiler warnings
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ConnectionConfig {
|
||||
Testnet,
|
||||
Mainnet,
|
||||
Betanet,
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<NetworkContext> for () {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkContext {
|
||||
pub connection_config: Option<common::ConnectionConfig>,
|
||||
pub connection_config: Option<ConnectionConfig>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
|
||||
|
||||
@@ -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<Option<String>> {
|
||||
fn input_network_name(_context: &ConnectionConfig) -> color_eyre::eyre::Result<Option<String>> {
|
||||
match inquire::Text::new("Input network name").prompt() {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(
|
||||
@@ -65,7 +68,7 @@ impl From<Submit> 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<
|
||||
<Self as interactive_clap::ToCli>::CliVariant,
|
||||
<Self as interactive_clap::FromCli>::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 <OnlineArgs as interactive_clap::FromCli>::from_cli(
|
||||
Some(cli_online_args),
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
|
||||
@@ -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<String> {
|
||||
#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<String> {
|
||||
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"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user