From 51f7f69957929dd2d9ff170a7ae9bc7242db5463 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Thu, 3 Oct 2024 16:42:27 +0200 Subject: [PATCH] color error in red and fix identity get with no indexer --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/commands/identity.rs | 22 +++++++++++++++++++--- src/main.rs | 3 ++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 224a7d0..be75fbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1061,6 +1061,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "combine" version = "3.8.1" @@ -2123,6 +2133,7 @@ dependencies = [ "bip39", "bs58", "clap", + "colored", "comfy-table", "confy", "directories 5.0.1", diff --git a/Cargo.toml b/Cargo.toml index 45a72ac..c302d75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,7 @@ nacl = { version = "^0.5.3" } # for old-style key gen # this is beta crate for password-encrypted files age = { default-features = false, version = "^0.10.0", features = ["armor"] } bip39 = { version = "^2.0.0", features = ["rand"] } # mnemonic +colored = "2.1.0" # allows to build gcli for different runtimes and with different predefined networks [features] diff --git a/src/commands/identity.rs b/src/commands/identity.rs index 27cb19f..c3481fa 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -338,9 +338,25 @@ pub async fn get_identity( .map(|i| i.issuer.unwrap().identity.unwrap().name.to_string()) .collect(), })), - _ => Err(GcliError::Indexer( - "Duniter and Indexer do not agree if x is smith".to_string(), - )), + (Some(s), None) => match indexer { + Some(_) => Err(GcliError::Indexer(format!( + "Duniter and Indexer do not agree if {index} is smith" + ))), + None => Ok(Some(SmithView { + status: s.status, + cert_issued_count: s.issued_certs.len(), + cert_issued: s.issued_certs.into_iter().map(|e| e.to_string()).collect(), + cert_received_count: s.received_certs.len(), + cert_received: s + .received_certs + .into_iter() + .map(|e| e.to_string()) + .collect(), + })), + }, + (None, Some(_)) => Err(GcliError::Indexer(format!( + "Duniter and Indexer do not agree if {pseudo} is smith" + ))), }?; // build view diff --git a/src/main.rs b/src/main.rs index d2fa91b..ba4857a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use anyhow::anyhow; use clap::builder::OsStr; use clap::Parser; use codec::Encode; +use colored::Colorize; use data::*; use display::DisplayEvent; use keys::*; @@ -187,7 +188,7 @@ async fn main() -> Result<(), GcliError> { Subcommand::Publish => commands::publish::handle_command().await, }; if let Err(ref e) = result { - println!("{}", e) + println!("{}", e.to_string().red()) } // still return result for detailed error message // println!(); -- GitLab