cargo-workspace2 0.2.2

A tool to query and manage complex cargo workspaces
Documentation
//! An op executor

use super::{versions, Print, Publish, PublishMod as Mod, PublishType};
use crate::models::{CrateId, DepGraph};
use semver::Version;
use std::path::PathBuf;

#[inline]
fn abs_path<'a>(root: &PathBuf, c_path: PathBuf, abs: bool) -> String {
    if abs {
        root.join(c_path).display().to_string()
    } else {
        c_path.display().to_string()
    }
}

/// A simple print executor
pub(super) fn print(p: Print, set: Vec<CrateId>, root: PathBuf, g: &mut DepGraph) {
    set.into_iter()
        .map(|id| g.get_crate(id))
        .map(|_crate| {
            let c_path = _crate.path().clone();

            match p {
                Print::Name => format!("{}", _crate.name()),
                Print::Path { abs } => format!("{}", abs_path(&root, c_path, abs)),
                Print::Both { abs } => {
                    format!("{}: {}", _crate.name(), abs_path(&root, c_path, abs))
                }
            }
        })
        .for_each(|s| println!("{}", s));
}