Skip to content

Commit

Permalink
Remove list all option from list subcommand, system-info does it better
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Jun 15, 2024
1 parent 39cab1b commit dce3cb9
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ use rokit::{discovery::discover_all_manifests, storage::Home, system::current_di
#[derive(Debug, Parser)]
pub struct ListSubcommand {
/// A specific tool identifier to list installed versions for.
#[clap(long, short, conflicts_with = "all")]
pub id: Option<ToolId>,
/// Lists all installed tools instead of tools in manifests.
#[clap(long, short, conflicts_with = "id")]
pub all: bool,
}

impl ListSubcommand {
pub async fn run(self, home: &Home) -> Result<()> {
let (header, lines) = if let Some(id) = self.id {
list_versions_for_id(home, &id)
} else if self.all {
list_versions_for_all(home)
} else {
list_versions(home).await
};
Expand Down Expand Up @@ -52,37 +46,6 @@ fn list_versions_for_id(home: &Home, id: &ToolId) -> (String, Vec<String>) {
}
}

// Lists all versions for all installed tools
fn list_versions_for_all(home: &Home) -> (String, Vec<String>) {
let cache = home.tool_cache();
let tools = cache
.all_installed_ids()
.into_iter()
.map(|id| (id.clone(), cache.all_installed_versions_for_id(&id)))
.collect::<Vec<_>>();

let bullet = style("•").dim();
let lines = tools
.into_iter()
.flat_map(|(id, mut versions)| {
versions.reverse(); // List newest versions first
let mut lines = vec![id.to_string()];
for version in versions {
lines.push(format!(" {bullet} {version}"));
}
lines
})
.collect::<Vec<_>>();

if lines.is_empty() {
let header = String::from("🛠️ No tools are installed.");
(header, Vec::new())
} else {
let header = String::from("🛠️ Installed tools:\n");
(header, lines)
}
}

// Lists versions for the current manifest, and the global manifest
async fn list_versions(home: &Home) -> (String, Vec<String>) {
let cwd = current_dir().await;
Expand Down

0 comments on commit dce3cb9

Please sign in to comment.