diff --git a/src/bin/detee-cli.rs b/src/bin/detee-cli.rs index 8cb1d98..bac0688 100644 --- a/src/bin/detee-cli.rs +++ b/src/bin/detee-cli.rs @@ -1,5 +1,6 @@ use clap::{builder::PossibleValue, Arg, ArgMatches, Command}; use clap_complete::{generate, Shell}; +use detee_cli::general::cli_handler::handle_operators; use detee_cli::sgx::cli_handler::handle_app; use detee_cli::snp::cli_handler::{handle_vm, handle_vm_nodes}; use detee_cli::*; @@ -618,39 +619,6 @@ fn handle_account(matches: &ArgMatches) { } } -fn handle_operators(matches: &ArgMatches) { - match matches.subcommand() { - Some(("list", _)) => { - cli_print(crate::operators::print_operators().map_err(Into::into)); - } - Some(("register", subcom_args)) => { - let escrow: u64 = *subcom_args.get_one::("escrow").unwrap(); - let email: String = subcom_args.get_one::("email").unwrap().clone(); - cli_print(crate::operators::register(escrow, email).map_err(Into::into)); - } - Some(("inspect", inspect_args)) => { - let wallet = match inspect_args.get_one::("wallet") { - Some(wallet) => wallet.to_string(), - None => config::Config::get_detee_wallet().unwrap_or("".to_string()), - }; - cli_print(crate::operators::inspect_operator(wallet).map_err(Into::into)); - } - Some(("kick", subcom_args)) => { - let uuid: String = subcom_args.get_one::("contract").unwrap().clone(); - let reason: String = subcom_args.get_one::("reason").unwrap().clone(); - cli_print(crate::operators::kick(uuid, reason).map_err(Into::into)); - } - Some(("ban-user", subcom_args)) => { - let user_wallet: String = subcom_args.get_one::("wallet").unwrap().clone(); - cli_print(crate::operators::ban(user_wallet).map_err(Into::into)); - } - Some(("decom", _)) => { - todo!("Currently decomissioning is not supported. Will be "); - } - _ => println!("To get more information about operators, use: detee-cli operator --help"), - } -} - fn handle_packagers( _matches: &ArgMatches, ) -> Result, Box> { diff --git a/src/general/cli_handler.rs b/src/general/cli_handler.rs new file mode 100644 index 0000000..bbec7bf --- /dev/null +++ b/src/general/cli_handler.rs @@ -0,0 +1,36 @@ +use super::operators; +use crate::{cli_print, config}; +use clap::ArgMatches; + +pub fn handle_operators(matches: &ArgMatches) { + match matches.subcommand() { + Some(("list", _)) => { + cli_print(operators::print_operators().map_err(Into::into)); + } + Some(("register", subcom_args)) => { + let escrow: u64 = *subcom_args.get_one::("escrow").unwrap(); + let email: String = subcom_args.get_one::("email").unwrap().clone(); + cli_print(operators::register(escrow, email).map_err(Into::into)); + } + Some(("inspect", inspect_args)) => { + let wallet = match inspect_args.get_one::("wallet") { + Some(wallet) => wallet.to_string(), + None => config::Config::get_detee_wallet().unwrap_or("".to_string()), + }; + cli_print(operators::inspect_operator(wallet).map_err(Into::into)); + } + Some(("kick", subcom_args)) => { + let uuid: String = subcom_args.get_one::("contract").unwrap().clone(); + let reason: String = subcom_args.get_one::("reason").unwrap().clone(); + cli_print(operators::kick(uuid, reason).map_err(Into::into)); + } + Some(("ban-user", subcom_args)) => { + let user_wallet: String = subcom_args.get_one::("wallet").unwrap().clone(); + cli_print(operators::ban(user_wallet).map_err(Into::into)); + } + Some(("decom", _)) => { + todo!("Currently decomissioning is not supported. Will be "); + } + _ => println!("To get more information about operators, use: detee-cli operator --help"), + } +} diff --git a/src/general/mod.rs b/src/general/mod.rs new file mode 100644 index 0000000..acc8bc5 --- /dev/null +++ b/src/general/mod.rs @@ -0,0 +1,3 @@ +pub mod cli_handler; +pub mod operators; +// pub mod grpc; diff --git a/src/operators.rs b/src/general/operators.rs similarity index 84% rename from src/operators.rs rename to src/general/operators.rs index 398fa24..7b2794f 100644 --- a/src/operators.rs +++ b/src/general/operators.rs @@ -26,12 +26,12 @@ impl From for TabledOperator { } } -pub fn register(escrow: u64, email: String) -> Result { +pub fn register(escrow: u64, email: String) -> Result { block_on(grpc::register_operator(escrow, email))?; - Ok(super::SimpleOutput::from("Successfully registered you as operator.")) + Ok(crate::SimpleOutput::from("Successfully registered you as operator.")) } -impl super::HumanOutput for brain::InspectOperatorResp { +impl crate::HumanOutput for brain::InspectOperatorResp { fn human_cli_print(&self) { match &self.operator { Some(op) => { @@ -65,7 +65,7 @@ pub fn inspect_operator(wallet: String) -> Result { +impl crate::HumanOutput for Vec { fn human_cli_print(&self) { let operators: Vec = self.iter().map(|op| op.clone().into()).collect(); @@ -80,14 +80,14 @@ pub fn print_operators() -> Result, grpc::Error> { Ok(block_on(grpc::list_operators())?) } -pub fn kick(contract_uuid: String, reason: String) -> Result { +pub fn kick(contract_uuid: String, reason: String) -> Result { let nano_lp = block_on(grpc::kick_contract(contract_uuid, reason))?; - Ok(super::SimpleOutput::from( + Ok(crate::SimpleOutput::from( format!("Successfully terminated contract. Refunded {} nanoLP.", nano_lp).as_str(), )) } -pub fn ban(wallet: String) -> Result { +pub fn ban(wallet: String) -> Result { block_on(grpc::ban_user(wallet))?; - Ok(super::SimpleOutput::from("Successfully banned user")) + Ok(crate::SimpleOutput::from("Successfully banned user")) } diff --git a/src/lib.rs b/src/lib.rs index 6b626db..002890f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ pub mod config; pub mod constants; +pub mod general; pub mod name_generator; -pub mod operators; pub mod packagers; pub mod sgx; pub mod snp;