From 074b0e55c138231fed8777aad45689de882d72d6 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 20 Jun 2023 15:45:14 +0200 Subject: [PATCH] cli: Add user alias to `rad auth` We were outputting `(me)` previously. --- radicle-cli/src/terminal/format.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/radicle-cli/src/terminal/format.rs b/radicle-cli/src/terminal/format.rs index a21812aa..a3c8e911 100644 --- a/radicle-cli/src/terminal/format.rs +++ b/radicle-cli/src/terminal/format.rs @@ -4,7 +4,7 @@ pub use radicle_term::format::*; pub use radicle_term::{style, Paint}; use radicle::cob::{ObjectId, Timestamp}; -use radicle::node::NodeId; +use radicle::node::{AliasStore, NodeId}; use radicle::prelude::Did; use radicle::profile::Profile; @@ -116,22 +116,25 @@ impl<'a> Identity<'a> { impl<'a> fmt::Display for Identity<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let username = "(me)"; + let nid = self.profile.id(); + let alias = self.profile.aliases().ok().and_then(|a| a.alias(nid)); let node_id = match self.short { - true => self::node(self.profile.id()), - false => self.profile.id().to_human(), + true => self::node(nid), + false => nid.to_human(), }; if self.styled { - write!( - f, - "{} {}", - term::format::highlight(node_id), - term::format::dim(username) - ) + write!(f, "{}", term::format::highlight(node_id))?; + if let Some(a) = alias { + write!(f, " {}", term::format::parens(term::format::dim(a)))?; + } } else { - write!(f, "{node_id} {username}") + write!(f, "{node_id}")?; + if let Some(a) = alias { + write!(f, " ({a})")?; + } } + Ok(()) } }