diff --git a/src/command/setup.rs b/src/command/setup.rs index 465e432..617d6fb 100644 --- a/src/command/setup.rs +++ b/src/command/setup.rs @@ -1,5 +1,7 @@ use crate::{settings, Result}; use clap::Args; +use colored_json::ToColoredJson; +use serde_json::json; #[derive(Args)] pub struct SetServerArgs { @@ -25,3 +27,12 @@ pub fn login(args: &LoginArgs) -> Result<()> { settings::put_str("password", &args.password)?; Ok(()) } + +#[derive(Args)] +pub struct StateArgs {} + +pub fn state(_: &StateArgs) -> Result<()> { + let state = json!({ "server": settings::get_str("api_url")?, "password": settings::get_str("password")? }); + println!("{}", serde_json::to_string(&state)?.to_colored_json_auto()?); + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index d6fe7f0..b8ea012 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ enum Commands { // Setup SetServer(command::setup::SetServerArgs), Login(command::setup::LoginArgs), + State(command::setup::StateArgs), // Admin AddAdmin(command::admin::AddAdminArgs), AddAllowedAction(command::admin::AddAllowedActionArgs), @@ -67,6 +68,10 @@ fn main() -> Result<()> { return command::setup::login(args); } + if let Some(Commands::State(args)) = &cli.command { + return command::setup::state(args); + } + if settings::get_str("password")?.is_empty() { Err("you need to login first, run btcmap-cli login ")?; } @@ -80,6 +85,7 @@ fn main() -> Result<()> { // Setup Commands::SetServer(_) => Err("supposed to be unreachable".into()), Commands::Login(_) => Err("supposed to be unreachable".into()), + Commands::State(_) => Err("supposed to be unreachable".into()), // Admin Commands::AddAdmin(args) => command::admin::add_admin(args), Commands::AddAllowedAction(args) => command::admin::add_allowed_action(args),