Skip to content

Commit

Permalink
Improve output for list and trust subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 25, 2024
1 parent 1b315b7 commit f547514
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -17,9 +18,10 @@ impl ListSubcommand {
.collect::<Vec<_>>();

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

Expand All @@ -29,8 +31,11 @@ impl ListSubcommand {
.collect::<Vec<_>>()
.join(", ");

println!("{id}\n {vers}");
lines.push(id.to_string());
lines.push(format!(" {vers}"));
}

info!("{}", lines.join("\n"));
}

Ok(())
Expand Down
32 changes: 23 additions & 9 deletions src/cli/trust.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{bail, Result};
use clap::Parser;
use tracing::info;

use aftman::{storage::Home, tool::ToolId};

Expand All @@ -22,17 +23,30 @@ impl TrustSubcommand {
.into_iter()
.partition::<Vec<_>, _>(|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(())
Expand Down

0 comments on commit f547514

Please sign in to comment.