summaryrefslogtreecommitdiffstats
path: root/src/commands/tree_of.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-01-13 21:30:57 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-01-15 23:17:39 +0100
commitf330587fec0cdf2f041531d5e7aea1e4f525e11b (patch)
tree8a2c92466fe8156ac5f54c6871fea271e768e55d /src/commands/tree_of.rs
parent4cf5a22ad1b0f5bf8f4e2c06c689ad40230e4387 (diff)
Reimplement tree printing using 'ptree'
This patch reimplements the tree-printing using the 'ptree' crate. Because ptree wants the tree item to implement `Clone`, a wrapper type is added which then implements `Clone` and `ptree::TreeItem` Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/tree_of.rs')
-rw-r--r--src/commands/tree_of.rs13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/commands/tree_of.rs b/src/commands/tree_of.rs
index 0db3978..d357ce8 100644
--- a/src/commands/tree_of.rs
+++ b/src/commands/tree_of.rs
@@ -8,8 +8,7 @@
// SPDX-License-Identifier: EPL-2.0
//
-use std::io::Write;
-
+use anyhow::Error;
use anyhow::Result;
use clap::ArgMatches;
use resiter::AndThen;
@@ -24,14 +23,6 @@ pub async fn tree_of(matches: &ArgMatches, repo: Repository, progressbars: Progr
let pname = matches.value_of("package_name").map(String::from).map(PackageName::from);
let pvers = matches.value_of("package_version").map(String::from).map(PackageVersionConstraint::new).transpose()?;
- fn print_package_tree(out: &mut dyn Write, indent: usize, tree: Tree) -> Result<()> {
- for (pkg, tree) in tree.into_iter() {
- writeln!(out, "{:indent$}{name} {version}", "", indent = indent, name = pkg.name(), version = pkg.version())?;
- print_package_tree(out, indent + 2, tree)?;
- }
- Ok(())
- }
-
repo.packages()
.filter(|p| pname.as_ref().map(|n| p.name() == n).unwrap_or(true))
.filter(|p| pvers.as_ref().map(|v| v.matches(p.version())).unwrap_or(true))
@@ -46,7 +37,7 @@ pub async fn tree_of(matches: &ArgMatches, repo: Repository, progressbars: Progr
let stdout = std::io::stdout();
let mut outlock = stdout.lock();
- print_package_tree(&mut outlock, 0, tree)
+ tree.display().iter().try_for_each(|d| ptree::write_tree(d, &mut outlock).map_err(Error::from))
})
.collect::<Result<()>>()
}