refactor: addressed compiler warnings

This commit is contained in:
Vlad Frolov 2023-06-02 22:10:37 +02:00
parent a844585c61
commit 0af8a4aca7
7 changed files with 32 additions and 32 deletions

View file

@ -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)
}
}

View file

@ -1,6 +0,0 @@
#[derive(Debug, Clone)]
pub enum ConnectionConfig {
Testnet,
Mainnet,
Betanet,
}

View file

@ -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

View file

@ -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)]

View file

@ -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),