Skip to content

Commit

Permalink
feat(cli/search): implement search command
Browse files Browse the repository at this point in the history
  • Loading branch information
comfysage committed Jan 26, 2024
1 parent ddf2da9 commit 16b5dd6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions saku-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod env;
pub mod config;
pub mod show;
pub mod search;
pub mod install;
pub mod add;
pub mod remove;
Expand Down
22 changes: 22 additions & 0 deletions saku-cli/src/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use saku_lib::pkg::data;
use saku_lib::prelude::*;
use saku_lib::util::path;

pub fn search(pattern: &str) -> Result<()> {
let pkgs: Vec<[String;2]> = path::pkg_match(&pattern)?;
if pkgs.len() == 0 {
return Err(make_err!(NotFound, "no packages matching that name were found"))
}

pkgs.iter().map(
|p| {
let (group, name) = (p[0].clone(), p[1].clone());
debug!("found pkg {}/{}", &group, &name);
let path = path::path_pkg(&group, &name);
let pkg = data::get_pkg_from_path(&path)?;
pkg.show()?;
Ok(())
}).collect::<Result<()>>()?;

Ok(())
}
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ fn get_commands() -> Command {
.arg_required_else_help(true)
.arg(arg!(<NAME> ... "Package to show")),
)
.subcommand(
Command::new("search")
.about("search for a package")
.arg_required_else_help(true)
.arg(arg!(<NAME> ... "Pattern to search for")),
)
.subcommand(
Command::new("list")
.about("List flasks")
Expand Down Expand Up @@ -259,6 +265,12 @@ fn main() -> Result<()> {
}
paths.iter().map(|name| cli::show::show(name)).collect()
}
Some(("search", sub_matches)) => {
let pattern = sub_matches.get_one::<String>("NAME").ok_or(make_err!(Missing, "pattern missing"))?;
saku_cli::search::search(&pattern)?;

Ok(())
}
Some(("list", sub_matches)) => {
let flag: Option<&bool> = sub_matches.get_one("installed");
if flag.is_some() {
Expand Down

0 comments on commit 16b5dd6

Please sign in to comment.