refactor: cli handle operator and operator.rs moved to general module
This commit is contained in:
parent
de8f761e1f
commit
36df27f3e6
@ -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::<u64>("escrow").unwrap();
|
||||
let email: String = subcom_args.get_one::<String>("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::<String>("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::<String>("contract").unwrap().clone();
|
||||
let reason: String = subcom_args.get_one::<String>("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::<String>("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<Vec<crate::packagers::Packager>, Box<dyn Error>> {
|
||||
|
36
src/general/cli_handler.rs
Normal file
36
src/general/cli_handler.rs
Normal file
@ -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::<u64>("escrow").unwrap();
|
||||
let email: String = subcom_args.get_one::<String>("email").unwrap().clone();
|
||||
cli_print(operators::register(escrow, email).map_err(Into::into));
|
||||
}
|
||||
Some(("inspect", inspect_args)) => {
|
||||
let wallet = match inspect_args.get_one::<String>("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::<String>("contract").unwrap().clone();
|
||||
let reason: String = subcom_args.get_one::<String>("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::<String>("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"),
|
||||
}
|
||||
}
|
3
src/general/mod.rs
Normal file
3
src/general/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod cli_handler;
|
||||
pub mod operators;
|
||||
// pub mod grpc;
|
@ -26,12 +26,12 @@ impl From<grpc::brain::ListOperatorsResp> for TabledOperator {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(escrow: u64, email: String) -> Result<super::SimpleOutput, grpc::Error> {
|
||||
pub fn register(escrow: u64, email: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
||||
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<brain::InspectOperatorResp, gr
|
||||
block_on(grpc::inspect_operator(wallet))
|
||||
}
|
||||
|
||||
impl super::HumanOutput for Vec<brain::ListOperatorsResp> {
|
||||
impl crate::HumanOutput for Vec<brain::ListOperatorsResp> {
|
||||
fn human_cli_print(&self) {
|
||||
let operators: Vec<TabledOperator> = self.iter().map(|op| op.clone().into()).collect();
|
||||
|
||||
@ -80,14 +80,14 @@ pub fn print_operators() -> Result<Vec<brain::ListOperatorsResp>, grpc::Error> {
|
||||
Ok(block_on(grpc::list_operators())?)
|
||||
}
|
||||
|
||||
pub fn kick(contract_uuid: String, reason: String) -> Result<super::SimpleOutput, grpc::Error> {
|
||||
pub fn kick(contract_uuid: String, reason: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
||||
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<super::SimpleOutput, grpc::Error> {
|
||||
pub fn ban(wallet: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
||||
block_on(grpc::ban_user(wallet))?;
|
||||
Ok(super::SimpleOutput::from("Successfully banned user"))
|
||||
Ok(crate::SimpleOutput::from("Successfully banned user"))
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user