diff --git a/saku-cli/src/list.rs b/saku-cli/src/list.rs index 14bd429..3333b8d 100644 --- a/saku-cli/src/list.rs +++ b/saku-cli/src/list.rs @@ -1,7 +1,8 @@ use saku_lib::pkg::data; use saku_lib::pkg::flask::Flask; +use saku_lib::pkg::pkg::Pkg; use saku_lib::prelude::*; -use saku_lib::util::msg; +use saku_lib::util::{msg, path}; pub fn list() -> Result<()> { let flask_files = data::get_flasks()?; @@ -21,3 +22,22 @@ pub fn list() -> Result<()> { Ok(()) } + +pub fn list_installed() -> Result<()> { + let dirs = path::get_store_dirs()?; + + let pkgs: Vec> = dirs + .iter() + .map(|name| data::get_pkg(&name)) + .collect(); + + for p in &pkgs { + if let Ok(pkg) = p { + println!(" - {} from {}", msg::general::name_f(&pkg.name), msg::general::url_f(&pkg.url)); + } else if let Err(err) = p { + warn!("error while listing pkg: {err}"); + } + } + + Ok(()) +} diff --git a/saku-lib/util/path.rs b/saku-lib/util/path.rs index 3a07e94..45b1aaf 100644 --- a/saku-lib/util/path.rs +++ b/saku-lib/util/path.rs @@ -225,3 +225,18 @@ pub fn flasks() -> Result> { Ok(files) } + +pub fn get_store_dirs() -> Result> { + let mut dirs = vec![]; + for d in fs::read_dir(&*constants::STORE_DIR)? { + let d = d?; + let d_path_bind = d.path(); + let d_path = match d_path_bind.to_str() { + Some(s) => Ok(s), + None => Err(Error::Unexpected), + }?; + let name = filepath::base_name(d_path)?; + dirs.push(name); + } + Ok(dirs) +} diff --git a/src/main.rs b/src/main.rs index ed5f865..b8350d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,8 +270,7 @@ fn main() -> Result<()> { Some(("list", sub_matches)) => { let flag = sub_matches.get_one::("installed").ok_or(make_err!())?; if *flag > 0 { - info!("installed is true"); - + saku_cli::list::list_installed()?; return Ok(()); }