summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2019-04-30 14:39:39 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2019-04-30 16:30:49 +0200
commit030dd838277e7868a1f73b0edf518fa4b0849c2d (patch)
tree2d83b040d27187b5c80cd2e7b021508ad1c59b6e
parent632b7e43de2df4f90da0fe14d85fae8aac13b151 (diff)
downloadrepolocli-030dd838277e7868a1f73b0edf518fa4b0849c2d.tar.gz
repolocli-030dd838277e7868a1f73b0edf518fa4b0849c2d.tar.xz
Add: Feature to sort output
-rw-r--r--Cargo.toml3
-rw-r--r--src/cli.rs34
-rw-r--r--src/main.rs52
3 files changed, 74 insertions, 15 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a6db2ea..eb89953 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ flexi_logger = "0.11"
prettytable-rs = "0.8"
filters = "0.3"
boolinator = "2"
+itertools = "0.8"
[dependencies.clap]
version = ">=2.33"
@@ -32,4 +33,4 @@ optional = true
[features]
default = ["compare_csv"]
-compare_csv = ["csv"] \ No newline at end of file
+compare_csv = ["csv"]
diff --git a/src/cli.rs b/src/cli.rs
index cf06dbe..c04052c 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -62,6 +62,23 @@ pub fn build_cli<'a>() -> App<'a, 'a> {
.takes_value(true)
.help("Query data about a project")
)
+
+ .arg(Arg::with_name("sort-version")
+ .long("sort-version")
+ .required(false)
+ .multiple(false)
+ .takes_value(false)
+ .help("Sort output by version")
+ .conflicts_with("sort-repo")
+ )
+ .arg(Arg::with_name("sort-repo")
+ .long("sort-repo")
+ .required(false)
+ .multiple(false)
+ .takes_value(false)
+ .help("Sort output by repository")
+ .conflicts_with("sort-version")
+ )
)
.subcommand(SubCommand::with_name("problems")
@@ -89,6 +106,23 @@ pub fn build_cli<'a>() -> App<'a, 'a> {
.args(&["repo", "maintainer"])
.required(true))
+
+ .arg(Arg::with_name("sort-maintainer")
+ .long("sort-maintainer")
+ .required(false)
+ .multiple(false)
+ .takes_value(false)
+ .help("Sort output by maintainer")
+ .conflicts_with("sort-repo")
+ )
+ .arg(Arg::with_name("sort-repo")
+ .long("sort-repo")
+ .required(false)
+ .multiple(false)
+ .takes_value(false)
+ .help("Sort output by repository")
+ .conflicts_with("sort-maintainer")
+ )
)
.subcommand(SubCommand::with_name("compare")
diff --git a/src/main.rs b/src/main.rs
index 82236a8..a45ebb7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,6 +7,7 @@ extern crate xdg;
extern crate flexi_logger;
extern crate filters;
extern crate boolinator;
+extern crate itertools;
#[cfg(feature = "compare_csv")]
extern crate csv;
@@ -34,6 +35,7 @@ use failure::Fallible as Result;
use clap::ArgMatches;
use filters::filter::Filter;
use boolinator::Boolinator;
+use itertools::Itertools;
use config::Configuration;
use compare::ComparePackage;
@@ -160,11 +162,22 @@ fn app() -> Result<()> {
mtch.value_of("project_name").unwrap() // safe by clap
};
- let packages = backend
- .project(&name)?
- .into_iter()
- .filter(|package| repository_filter.filter(package.repo()))
- .collect();
+ let packages = {
+ let iter = backend
+ .project(&name)?
+ .into_iter()
+ .filter(|package| repository_filter.filter(package.repo()));
+
+ if mtch.is_present("sort-versions"){
+ iter.sorted_by(|a, b| Ord::cmp(a.version(), b.version()))
+ .collect()
+ } else if mtch.is_present("sort-repo") {
+ iter.sorted_by(|a, b| Ord::cmp(a.repo(), b.repo()))
+ .collect()
+ } else {
+ iter.collect()
+ }
+ };
frontend.list_packages(packages)
},
("problems", Some(mtch)) => {
@@ -173,15 +186,26 @@ fn app() -> Result<()> {
let repo = mtch.value_of("repo");
let maintainer = mtch.value_of("maintainer");
- let problems = match (repo, maintainer) {
- (Some(r), None) => backend.problems_for_repo(&r)?,
- (None, Some(m)) => backend.problems_for_maintainer(&m)?,
- (None, None) => unimplemented!(),
- (Some(_), Some(_)) => unimplemented!(),
- }
- .into_iter()
- .filter(|problem| repository_filter.filter(problem.repo()))
- .collect();
+ let problems = {
+ let iter = match (repo, maintainer) {
+ (Some(r), None) => backend.problems_for_repo(&r)?,
+ (None, Some(m)) => backend.problems_for_maintainer(&m)?,
+ (None, None) => unimplemented!(),
+ (Some(_), Some(_)) => unimplemented!(),
+ }
+ .into_iter()
+ .filter(|problem| repository_filter.filter(problem.repo()));
+
+ if mtch.is_present("sort-maintainer") {
+ iter.sorted_by(|a, b| Ord::cmp(a.maintainer(), b.maintainer()))
+ .collect()
+ } else if mtch.is_present("sort-repo") {
+ iter.sorted_by(|a, b| Ord::cmp(a.repo(), b.repo()))
+ .collect()
+ } else {
+ iter.collect()
+ }
+ };
frontend.list_problems(problems)
},