1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use clap::Parser;
#[derive(Debug, Copy, Clone, Parser)]
pub struct List {}
impl List {
pub fn execute(&self) -> Result<(), anyhow::Error> {
use prettytable::{format, row, Table};
let rows = wasmer_registry::get_all_local_packages(None)
.into_iter()
.filter_map(|pkg| {
let package_root_path = pkg.get_path().ok()?;
let (manifest, _) =
wasmer_registry::get_executable_file_from_path(&package_root_path, None)
.ok()?;
let commands = manifest
.command
.unwrap_or_default()
.iter()
.map(|c| c.get_name())
.collect::<Vec<_>>()
.join(" \r\n");
Some(row![pkg.registry, pkg.name, pkg.version, commands])
})
.collect::<Vec<_>>();
let empty_table = rows.is_empty();
let mut table = Table::init(rows);
table.set_titles(row!["Registry", "Package", "Version", "Commands"]);
table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_format(*format::consts::FORMAT_NO_COLSEP);
if empty_table {
table.add_empty_row();
}
let _ = table.printstd();
Ok(())
}
}