diff --git a/src/lib.rs b/src/lib.rs index a2da8b909..8ddebb38d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,6 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod config; -mod diff; pub mod error; pub mod ops; -pub mod shell; pub mod steps; diff --git a/src/ops/cargo.rs b/src/ops/cargo.rs index c9e8b3568..64b6c14b8 100644 --- a/src/ops/cargo.rs +++ b/src/ops/cargo.rs @@ -180,8 +180,12 @@ pub fn set_workspace_version( if dry_run { if manifest != original_manifest { - let diff = - crate::diff::unified_diff(&original_manifest, &manifest, manifest_path, "updated"); + let diff = crate::ops::diff::unified_diff( + &original_manifest, + &manifest, + manifest_path, + "updated", + ); log::debug!("change:\n{diff}"); } } else { @@ -278,8 +282,12 @@ pub fn set_package_version(manifest_path: &Path, version: &str, dry_run: bool) - if dry_run { if manifest != original_manifest { - let diff = - crate::diff::unified_diff(&original_manifest, &manifest, manifest_path, "updated"); + let diff = crate::ops::diff::unified_diff( + &original_manifest, + &manifest, + manifest_path, + "updated", + ); log::debug!("change:\n{diff}"); } } else { @@ -314,8 +322,12 @@ pub fn upgrade_dependency_req( let manifest = manifest.to_string(); if manifest != original_manifest { if dry_run { - let diff = - crate::diff::unified_diff(&original_manifest, &manifest, manifest_path, "updated"); + let diff = crate::ops::diff::unified_diff( + &original_manifest, + &manifest, + manifest_path, + "updated", + ); log::debug!("change:\n{diff}"); } else { atomic_write(manifest_path, &manifest)?; diff --git a/src/diff.rs b/src/ops/diff.rs similarity index 100% rename from src/diff.rs rename to src/ops/diff.rs diff --git a/src/ops/mod.rs b/src/ops/mod.rs index d7b9c7469..07628b0e0 100644 --- a/src/ops/mod.rs +++ b/src/ops/mod.rs @@ -5,3 +5,5 @@ pub mod index; pub mod replace; pub mod shell; pub mod version; + +pub(crate) mod diff; diff --git a/src/ops/replace.rs b/src/ops/replace.rs index ec0209ca1..635dfa34f 100644 --- a/src/ops/replace.rs +++ b/src/ops/replace.rs @@ -124,7 +124,7 @@ pub fn do_file_replacements( format!( "in {}\n{}", path.display(), - crate::diff::unified_diff(&data, &replaced, &path, "replaced") + crate::ops::diff::unified_diff(&data, &replaced, &path, "replaced") ), ); } else { diff --git a/src/shell.rs b/src/shell.rs deleted file mode 100644 index 978f63aab..000000000 --- a/src/shell.rs +++ /dev/null @@ -1,72 +0,0 @@ -use std::io::Write; - -use anyhow::Context as _; -pub use termcolor::{Color, ColorChoice}; -use termcolor::{ColorSpec, StandardStream, WriteColor}; - -use crate::error::CargoResult; - -/// Whether to color logged output -fn colorize_stderr() -> ColorChoice { - if concolor_control::get(concolor_control::Stream::Stderr).color() { - ColorChoice::Always - } else { - ColorChoice::Never - } -} - -/// Print a message with a colored title in the style of Cargo shell messages. -pub fn print( - status: &str, - message: impl std::fmt::Display, - color: Color, - justified: bool, -) -> CargoResult<()> { - let color_choice = colorize_stderr(); - let mut output = StandardStream::stderr(color_choice); - - output.set_color(ColorSpec::new().set_fg(Some(color)).set_bold(true))?; - if justified { - write!(output, "{status:>12}")?; - } else { - write!(output, "{}", status)?; - output.set_color(ColorSpec::new().set_bold(true))?; - write!(output, ":")?; - } - output.reset()?; - - writeln!(output, " {message}").with_context(|| "Failed to write message")?; - - Ok(()) -} - -/// Print a styled action message. -pub fn status(action: &str, message: impl std::fmt::Display) -> CargoResult<()> { - print(action, message, Color::Green, true) -} - -/// Print a styled error message. -pub fn error(message: impl std::fmt::Display) -> CargoResult<()> { - print("error", message, Color::Red, false) -} - -/// Print a styled warning message. -pub fn warn(message: impl std::fmt::Display) -> CargoResult<()> { - print("warning", message, Color::Yellow, false) -} - -/// Print a styled warning message. -pub fn note(message: impl std::fmt::Display) -> CargoResult<()> { - print("note", message, Color::Cyan, false) -} - -/// Print a part of a line with formatting -pub fn write_stderr(fragment: impl std::fmt::Display, spec: &ColorSpec) -> CargoResult<()> { - let color_choice = colorize_stderr(); - let mut output = StandardStream::stderr(color_choice); - - output.set_color(spec)?; - write!(output, "{}", fragment)?; - output.reset()?; - Ok(()) -} diff --git a/src/steps/commit.rs b/src/steps/commit.rs index 1c25d0d66..09ee0e799 100644 --- a/src/steps/commit.rs +++ b/src/steps/commit.rs @@ -93,7 +93,7 @@ impl CommitStep { if ws_config.is_workspace { let consolidate_commits = super::consolidate_commits(&selected_pkgs, &excluded_pkgs)?; if !consolidate_commits { - let _ = crate::shell::warn( + let _ = crate::ops::shell::warn( "ignoring `consolidate-commits=false`; `cargo release commit` can effectively only do one commit", ); }