add package search
This commit is contained in:
Generated
+20
-2
@@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "alpm"
|
||||
version = "2.2.1"
|
||||
@@ -295,6 +304,12 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.7.1"
|
||||
@@ -350,6 +365,7 @@ dependencies = [
|
||||
"clap",
|
||||
"criterion",
|
||||
"path-absolutize",
|
||||
"regex",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
@@ -447,10 +463,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.0"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
|
||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ anyhow = "*"
|
||||
# clap 4 until (at least) 4.0.32 have scrapped actual color support. we stay on 3.x until that's fixed.
|
||||
clap = "3.*"
|
||||
path-absolutize = "*"
|
||||
regex = "1.7.1"
|
||||
serde_json = "1.0.91"
|
||||
|
||||
[profile.release]
|
||||
|
||||
@@ -4,6 +4,7 @@ pub(crate) const GROUPS: &str = "groups";
|
||||
pub(crate) const IMPORT: &str = "import";
|
||||
pub(crate) const NEW: &str = "new";
|
||||
pub(crate) const REMOVE: &str = "remove";
|
||||
pub(crate) const SEARCH: &str = "search";
|
||||
pub(crate) const SHOW: &str = "show";
|
||||
pub(crate) const SYNC: &str = "sync";
|
||||
pub(crate) const UNMANAGED: &str = "unmanaged";
|
||||
|
||||
@@ -44,6 +44,12 @@ fn get_arg_parser() -> Command<'static> {
|
||||
.arg_required_else_help(true)
|
||||
.arg(Arg::new("groups").multiple_values(true)),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new(SEARCH)
|
||||
.about("search for packages which match a provided regex")
|
||||
.arg_required_else_help(true)
|
||||
.arg(Arg::new("string")),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new(SHOW)
|
||||
.about("show packages under an imported group")
|
||||
|
||||
+32
-1
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
||||
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use clap::ArgMatches;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::action;
|
||||
use crate::args;
|
||||
@@ -28,7 +29,6 @@ impl Pacdef {
|
||||
|
||||
#[allow(clippy::unit_arg)]
|
||||
pub fn run_action_from_arg(self) -> Result<()> {
|
||||
// TODO new
|
||||
// TODO review
|
||||
// TODO search
|
||||
match self.args.subcommand() {
|
||||
@@ -45,6 +45,9 @@ impl Pacdef {
|
||||
Some((action::SHOW, groups)) => {
|
||||
self.show_group_content(groups).context("showing groups")
|
||||
}
|
||||
Some((action::SEARCH, args)) => {
|
||||
self.search_packages(args).context("searching packages")
|
||||
}
|
||||
Some((action::SYNC, _)) => Ok(self.install_packages()),
|
||||
Some((action::UNMANAGED, _)) => Ok(self.show_unmanaged_packages()),
|
||||
Some((action::VERSION, _)) => Ok(self.show_version()),
|
||||
@@ -236,6 +239,34 @@ impl Pacdef {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn search_packages(&self, args: &ArgMatches) -> Result<()> {
|
||||
let search_string = args
|
||||
.get_one::<String>("string")
|
||||
.context("getting search string from arg")?;
|
||||
|
||||
let re = Regex::new(search_string)?;
|
||||
|
||||
let mut vec = vec![];
|
||||
|
||||
for group in &self.groups {
|
||||
for section in &group.sections {
|
||||
for package in §ion.packages {
|
||||
if re.is_match(&package.name) {
|
||||
vec.push((group, section, package))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec.sort_unstable();
|
||||
|
||||
for (g, s, p) in vec {
|
||||
println!("{}:{}:{}", g.name, s.name, p.name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn get_assumed_group_file_names(arg_match: &ArgMatches) -> Result<Vec<PathBuf>> {
|
||||
|
||||
Reference in New Issue
Block a user