summaryrefslogtreecommitdiffstats
path: root/src/commands/find_pkg.rs
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-11 12:38:12 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-06-16 13:16:28 +0200
commit0f83f5dcc71489428d3f2afa44cf7d29b9438289 (patch)
treeba9309acef9509799e1ec4c5493f6251645ccbbc /src/commands/find_pkg.rs
parent67580107cf087d06fb1e8bd0cd9fdc3074499b20 (diff)
Iterator adaptor for package printing mechanic
This implements a new interface for printing packages from an iterator. It can be used to implement parallel print-preparation. The new interface is used in the command implementation of the "find-pkg" subcommand. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands/find_pkg.rs')
-rw-r--r--src/commands/find_pkg.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/commands/find_pkg.rs b/src/commands/find_pkg.rs
index d45c946..8982911 100644
--- a/src/commands/find_pkg.rs
+++ b/src/commands/find_pkg.rs
@@ -16,10 +16,13 @@ use anyhow::Context;
use anyhow::Result;
use clap::ArgMatches;
use log::trace;
+use futures::stream::StreamExt;
+use futures::stream::TryStreamExt;
use crate::config::Configuration;
use crate::package::PackageVersionConstraint;
use crate::repository::Repository;
+use crate::ui::*;
/// Implementation of the "find_pkg" subcommand
pub async fn find_pkg(
@@ -85,6 +88,17 @@ pub async fn find_pkg(
};
let format = config.package_print_format();
- crate::ui::print_packages(&mut outlock, format, iter, config, &flags)
+ let hb = crate::ui::handlebars_for_package_printing(format)?;
+
+ tokio_stream::iter({
+ iter.enumerate()
+ .map(|(i, p)| p.prepare_print(config, &flags, &hb, i))
+ })
+ .map(|pp| pp.into_displayable())
+ .try_for_each(|p| {
+ let r = writeln!(&mut outlock, "{}", p).map_err(anyhow::Error::from);
+ futures::future::ready(r)
+ })
+ .await
}
}