M README.md => README.md +16 -1
@@ 77,7 77,22 @@ cabin help list
> -h, --help Print help
### Search
-Unimplemented
+```sh
+cabin search <query>
+```
+Search through package names, descriptions and urls and lists package names,versions and rels.
+
+```sh
+cabin help search
+```
+> Searches the database for a package with the name or containing the name
+> Usage: cabin search [OPTIONS] <QUERY>
+> Arguments:
+> <QUERY> search query
+> Options:
+> -d, --db <DB> package database path
+> -h, --help Print help
+
### Build
To build a given package in the repo,
M src/cmds/mod.rs => src/cmds/mod.rs +2 -0
@@ 3,8 3,10 @@ mod list;
mod info;
mod build;
mod tree;
+mod search;
pub use scan::scan;
pub use list::list;
pub use info::info;
pub use build::{build, build_all, build_multi};
pub use tree::tree;
+pub use search::search;
A src/cmds/search.rs => src/cmds/search.rs +16 -0
@@ 0,0 1,16 @@
+use std::path::PathBuf;
+use crate::types::Database;
+
+/// searches trough packages
+/// checks package name, description and url
+/// prints the package name, version and rel
+pub fn search(query: String, db: Option<PathBuf>) {
+ let db = Database::from_file(db.unwrap_or(PathBuf::from("db.yml")))
+ .expect("Unable to open database");
+
+ for (_, pkg) in db.packages.iter() {
+ if pkg.name.contains(&query) || pkg.description.contains(&query) || pkg.url.contains(&query){
+ println!("{}-{}-r{}", pkg.name, pkg.version, pkg.rel);
+ }
+ }
+}
M src/main.rs => src/main.rs +1 -1
@@ 134,6 134,6 @@ fn main() {
},
Commands::Tree { package, db, only_local } => cmds::tree(package, db, only_local),
Commands::BuildAll { arch, db, verbose } => cmds::build_all(db, arch, verbose),
- _ => panic!("Unimplemented")
+ Commands::Search { query, db } => cmds::search(query, db)
}
}