From f547514c8976aab0700de88c04dca3941087bc76 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Mon, 25 Mar 2024 13:59:49 +0100 Subject: [PATCH] Improve output for list and trust subcommands --- src/cli/list.rs | 11 ++++++++--- src/cli/trust.rs | 32 +++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/cli/list.rs b/src/cli/list.rs index f1b7f73..a0e9207 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -2,6 +2,7 @@ use anyhow::Result; use clap::Parser; use aftman::storage::Home; +use tracing::info; /// Lists all existing tools managed by Aftman. #[derive(Debug, Parser)] @@ -17,9 +18,10 @@ impl ListSubcommand { .collect::>(); if tools.is_empty() { - println!("No tools installed."); + info!("No tools installed."); } else { - println!("Installed tools:\n"); + let mut lines = vec![String::from("Installed tools:\n")]; + for (id, mut versions) in tools { versions.reverse(); // List newest versions first @@ -29,8 +31,11 @@ impl ListSubcommand { .collect::>() .join(", "); - println!("{id}\n {vers}"); + lines.push(id.to_string()); + lines.push(format!(" {vers}")); } + + info!("{}", lines.join("\n")); } Ok(()) diff --git a/src/cli/trust.rs b/src/cli/trust.rs index 674cade..d8cc290 100644 --- a/src/cli/trust.rs +++ b/src/cli/trust.rs @@ -1,5 +1,6 @@ use anyhow::{bail, Result}; use clap::Parser; +use tracing::info; use aftman::{storage::Home, tool::ToolId}; @@ -22,17 +23,30 @@ impl TrustSubcommand { .into_iter() .partition::, _>(|tool| cache.add_tool(tool.clone())); - if !added_tools.is_empty() { - println!("The following tools have been marked as trusted:"); - for tool in added_tools { - println!(" - {tool}"); + if added_tools.len() == 1 && existing_tools.is_empty() { + info!("Tool has been marked as trusted: {}", added_tools[0]); + } else if existing_tools.len() == 1 && added_tools.is_empty() { + info!("Tool was already trusted: {}", existing_tools[0]); + } else { + let mut lines = Vec::new(); + + if !added_tools.is_empty() { + lines.push(String::from( + "The following tools have been marked as trusted:", + )); + for tool in added_tools { + lines.push(format!(" - {tool}")); + } } - } - if !existing_tools.is_empty() { - println!("The following tools were already trusted:"); - for tool in existing_tools { - println!(" - {tool}"); + + if !existing_tools.is_empty() { + lines.push(String::from("The following tools were already trusted:")); + for tool in existing_tools { + lines.push(format!(" - {tool}")); + } } + + info!("{}", lines.join("\n")); } Ok(())