Skip to content

Commit

Permalink
Make it easier to examine local cache state
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 14, 2024
1 parent 26bdf40 commit 2081254
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/command/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{settings, Result};
use clap::Args;
use colored_json::ToColoredJson;
use serde_json::json;

#[derive(Args)]
pub struct SetServerArgs {
Expand All @@ -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(())
}
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 <password>")?;
}
Expand All @@ -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),
Expand Down

0 comments on commit 2081254

Please sign in to comment.