diff options
Diffstat (limited to 'development/tools/cargo-workspace2/src/ops/executor.rs')
-rw-r--r-- | development/tools/cargo-workspace2/src/ops/executor.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/development/tools/cargo-workspace2/src/ops/executor.rs b/development/tools/cargo-workspace2/src/ops/executor.rs new file mode 100644 index 000000000000..90a4f68303b1 --- /dev/null +++ b/development/tools/cargo-workspace2/src/ops/executor.rs @@ -0,0 +1,33 @@ +//! 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)); +} |