From 151d39b329729f0d36be7fbf466ab1bb8ee5ec18 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 20 Oct 2022 13:31:11 -0500 Subject: [PATCH] fix(cli): Mirror cargo's output --- Cargo.lock | 20 +++- Cargo.toml | 3 +- src/error.rs | 3 +- src/lib.rs | 1 + src/ops/cargo.rs | 25 +++-- src/ops/git.rs | 6 +- src/ops/replace.rs | 18 ++-- src/ops/shell.rs | 96 +++++++++++++++++-- src/shell.rs | 72 ++++++++++++++ src/steps/commit.rs | 2 +- src/steps/hook.rs | 6 +- src/steps/mod.rs | 94 ++++++++++-------- src/steps/owner.rs | 2 +- src/steps/publish.rs | 13 ++- src/steps/push.rs | 7 +- src/steps/release.rs | 46 ++++----- src/steps/replace.rs | 2 +- src/steps/tag.rs | 9 +- src/steps/version.rs | 37 ++++--- tests/version/downgrade_error/stderr.log | 2 +- tests/version/dry_run/stderr.log | 6 +- tests/version/ignore_dependent/stderr.log | 4 +- tests/version/set_absolute_version/stderr.log | 4 +- .../set_absolute_workspace_version/stderr.log | 10 +- tests/version/set_relative_version/stderr.log | 4 +- .../set_relative_workspace_version/stderr.log | 10 +- .../upgrade_compatible_dependency/stderr.log | 6 +- .../stderr.log | 6 +- tests/version/upgrade_workspace/stderr.log | 8 +- .../version/virtual_workspace_deps/stderr.log | 8 +- tests/version/workspace_deps/stderr.log | 8 +- .../workspace_version_exclude/stderr.log | 16 ++-- .../workspace_version_subset/stderr.log | 10 +- 33 files changed, 386 insertions(+), 178 deletions(-) create mode 100644 src/shell.rs diff --git a/Cargo.lock b/Cargo.lock index d19e0f80f..a3cb5dd57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,7 @@ dependencies = [ "cargo_metadata", "clap", "clap-cargo", + "concolor-control", "crates-index", "difflib", "dirs-next", @@ -306,9 +307,26 @@ checksum = "015267563b1df20adccdd00cb05257b1dfbea70a04928e9cf88ffb850c1a40af" dependencies = [ "atty", "bitflags", - "concolor-query", + "concolor-query 0.0.5", ] +[[package]] +name = "concolor-control" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7104119c2f80d887239879d0c50e033cd40eac9a3f3561e0684ba7d5d654f4da" +dependencies = [ + "atty", + "bitflags", + "concolor-query 0.0.4", +] + +[[package]] +name = "concolor-query" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad159cc964ac8f9d407cbc0aa44b02436c054b541f2b4b5f06972e1efdc54bc7" + [[package]] name = "concolor-query" version = "0.0.5" diff --git a/Cargo.toml b/Cargo.toml index 0a41717b7..bedb7c13d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ semver = "1.0" quick-error = "2.0" regex = "1.6" bstr = "1.0.1" -termcolor = "1.1" +termcolor = "1.1.3" maplit = "1.0" indexmap = "1.9" time = { version = "0.3", features = ["formatting", "macros"] } @@ -56,6 +56,7 @@ globset = { version = "0.4.9", default-features = false } dunce = "1.0.3" trycmd = "0.14.0" anyhow = "1.0.65" +concolor-control = { version = "0.0.7", features = ["auto"] } [dev-dependencies] assert_fs = "1.0" diff --git a/src/error.rs b/src/error.rs index a4b94619f..9b2e313b5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -63,10 +63,9 @@ pub fn report(result: Result<(), CliError>) -> i32 { Ok(()) => 0, Err(err) => { if let Some(error) = err.error { - use std::io::Write; // At this point, we might be exiting due to a broken pipe, just do our best and // move on. - let _ = writeln!(std::io::stderr(), "{}", error); + let _ = crate::ops::shell::error(error); } err.code } diff --git a/src/lib.rs b/src/lib.rs index c35283be0..1a7eb0e31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,4 +7,5 @@ pub mod config; 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 4e159259e..c1c8a1726 100644 --- a/src/ops/cargo.rs +++ b/src/ops/cargo.rs @@ -131,7 +131,10 @@ pub fn wait_for_publish( } if !logged { - log::info!("Waiting for publish to complete..."); + let _ = crate::ops::shell::status( + "Waiting", + format!("on {name} to propagate to index"), + ); logged = true; } std::thread::sleep(sleep_time); @@ -229,7 +232,10 @@ pub fn ensure_owners( let missing = expected.difference(¤t).copied().collect::>(); if !missing.is_empty() { - log::info!("Adding owners for {}: {}", name, missing.join(", ")); + let _ = crate::ops::shell::status( + "Adding", + format!("owners for {}: {}", name, missing.join(", ")), + ); if !dry_run { let mut cmd = std::process::Command::new(&cargo); cmd.arg("owner").arg(name).arg("--color=never"); @@ -244,11 +250,11 @@ pub fn ensure_owners( if !output.status.success() { // HACK: Can't error as the user might not have permission to set owners and we can't // tell what the error was without parsing it - log::warn!( + let _ = crate::ops::shell::warn(format!( "Failed to set owners for {}: {}", name, String::from_utf8_lossy(&output.stderr) - ); + )); } } } @@ -451,11 +457,12 @@ fn upgrade_req( } }; - log::info!( - "Updating {}'s dependency from {} to {}", - manifest_name, - existing_req_str, - new_req, + let _ = crate::ops::shell::status( + "Updating", + format!( + "{}'s dependency from {} to {}", + manifest_name, existing_req_str, new_req + ), ); *version_value = toml_edit::value(new_req); true diff --git a/src/ops/git.rs b/src/ops/git.rs index 4aa9f3f9c..975397f7c 100644 --- a/src/ops/git.rs +++ b/src/ops/git.rs @@ -36,7 +36,8 @@ pub fn is_behind_remote(dir: &Path, remote: &str, branch: &str) -> CargoResult { - log::warn!("Push target `{}` doesn't exist", remote_branch); + let _ = + crate::ops::shell::warn(format!("Push target `{}` doesn't exist", remote_branch)); log::trace!("Error {}", err); false } @@ -63,7 +64,8 @@ pub fn is_local_unchanged(dir: &Path, remote: &str, branch: &str) -> CargoResult base_id != branch_id } Err(err) => { - log::warn!("Push target `{}` doesn't exist", remote_branch); + let _ = + crate::ops::shell::warn(format!("Push target `{}` doesn't exist", remote_branch)); log::trace!("Error {}", err); false } diff --git a/src/ops/replace.rs b/src/ops/replace.rs index 13496240a..7c2d42e07 100644 --- a/src/ops/replace.rs +++ b/src/ops/replace.rs @@ -80,7 +80,6 @@ pub fn do_file_replacements( for (path, replaces) in by_file.into_iter() { let file = cwd.join(&path); - log::info!("Applying replacements for {}", path.display()); if !file.exists() { anyhow::bail!("Unable to find file {} to perform replace", file.display()); } @@ -135,12 +134,19 @@ pub fn do_file_replacements( "replaced", 0, ); - let level = if noisy { - log::Level::Info + if noisy { + let _ = crate::ops::shell::status( + "Replacing", + format!( + "in {}\n{}", + path.display(), + itertools::join(diff.into_iter(), "") + ), + ); } else { - log::Level::Debug - }; - log::log!(level, "Change:\n{}", itertools::join(diff.into_iter(), "")); + let _ = + crate::ops::shell::status("Replacing", format!("in {}", path.display())); + } } else { std::fs::write(&file, replaced)?; } diff --git a/src/ops/shell.rs b/src/ops/shell.rs index 98f13c8a0..e3ba63144 100644 --- a/src/ops/shell.rs +++ b/src/ops/shell.rs @@ -1,6 +1,22 @@ use std::io::{stdin, stdout, Write}; -use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; +use anyhow::Context as _; +use termcolor::{ColorChoice, ColorSpec, StandardStream, WriteColor}; + +pub use termcolor::Color; + +use crate::error::CargoResult; + +pub fn confirm(prompt: &str) -> bool { + let mut input = String::new(); + + console_println(&format!("{} [y/N] ", prompt), None, true); + + stdout().flush().unwrap(); + stdin().read_line(&mut input).expect("y/n required"); + + input.trim().to_lowercase() == "y" +} fn console_println(text: &str, color: Option, bold: bool) { let mut stdout = StandardStream::stdout(ColorChoice::Auto); @@ -13,13 +29,79 @@ fn console_println(text: &str, color: Option, bold: bool) { stdout.reset().unwrap(); } -pub fn confirm(prompt: &str) -> bool { - let mut input = String::new(); +/// Whether to color logged output +fn colorize_stderr() -> ColorChoice { + if concolor_control::get(concolor_control::Stream::Stderr).color() { + ColorChoice::Always + } else { + ColorChoice::Never + } +} - console_println(&format!("{} [y/N] ", prompt), None, true); +/// 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); - stdout().flush().unwrap(); - stdin().read_line(&mut input).expect("y/n required"); + 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()?; - input.trim().to_lowercase() == "y" + 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) +} + +pub fn log(level: log::Level, message: impl std::fmt::Display) -> CargoResult<()> { + match level { + log::Level::Error => error(message), + log::Level::Warn => warn(message), + log::Level::Info => note(message), + _ => { + log::log!(level, "{}", message); + Ok(()) + } + } +} + +/// 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/shell.rs b/src/shell.rs new file mode 100644 index 000000000..978f63aab --- /dev/null +++ b/src/shell.rs @@ -0,0 +1,72 @@ +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 1527ca32a..c37dcc305 100644 --- a/src/steps/commit.rs +++ b/src/steps/commit.rs @@ -57,7 +57,7 @@ impl CommitStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if crate::ops::git::is_dirty(ws_meta.workspace_root.as_std_path())?.is_none() { - log::info!("Nothing to commit."); + let _ = crate::ops::shell::error("Nothing to commit"); return Err(2.into()); } diff --git a/src/steps/hook.rs b/src/steps/hook.rs index 16f90e79e..3d1685425 100644 --- a/src/steps/hook.rs +++ b/src/steps/hook.rs @@ -96,7 +96,7 @@ impl HookStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } @@ -189,10 +189,10 @@ pub fn hook( // we use dry_run environmental variable to run the script // so here we set dry_run=false and always execute the command. if !cmd::call_with_env(pre_rel_hook, envs, cwd, false)? { - log::error!( + let _ = crate::ops::shell::error(format!( "Release of {} aborted by non-zero return of prerelease hook.", crate_name - ); + )); return Err(101.into()); } } diff --git a/src/steps/mod.rs b/src/steps/mod.rs index 27895611e..42b843372 100644 --- a/src/steps/mod.rs +++ b/src/steps/mod.rs @@ -22,10 +22,12 @@ pub fn verify_git_is_clean( ) -> Result { let mut success = true; if let Some(dirty) = crate::ops::git::is_dirty(path)? { - log::log!( + let _ = crate::ops::shell::log( level, - "Uncommitted changes detected, please resolve before release:\n {}", - dirty.join("\n ") + format!( + "Uncommitted changes detected, please resolve before release:\n {}", + dirty.join("\n ") + ), ); if level == log::Level::Error { success = false; @@ -52,11 +54,9 @@ pub fn verify_tags_missing( let cwd = &pkg.package_root; if crate::ops::git::tag_exists(cwd, tag_name)? { let crate_name = pkg.meta.name.as_str(); - log::log!( + let _ = crate::ops::shell::log( level, - "Tag `{}` already exists (for `{}`)", - tag_name, - crate_name + format!("Tag `{}` already exists (for `{}`)", tag_name, crate_name), ); tag_exists = true; } @@ -88,11 +88,9 @@ pub fn verify_tags_exist( let cwd = &pkg.package_root; if !crate::ops::git::tag_exists(cwd, tag_name)? { let crate_name = pkg.meta.name.as_str(); - log::log!( + let _ = crate::ops::shell::log( level, - "Tag `{}` doesn't exist (for `{}`)", - tag_name, - crate_name + format!("Tag `{}` doesn't exist (for `{}`)", tag_name, crate_name), ); tag_missing = true; } @@ -127,11 +125,13 @@ pub fn verify_git_branch( let good_branches = good_branches.build()?; let good_branch_match = good_branches.matched_path_or_any_parents(&branch, false); if !good_branch_match.is_ignore() { - log::log!( + let _ = crate::ops::shell::log( level, - "Cannot release from branch {:?}, instead switch to {:?}", - branch, - ws_config.allow_branch().join(", ") + format!( + "Cannot release from branch {:?}, instead switch to {:?}", + branch, + ws_config.allow_branch().join(", ") + ), ); log::trace!("Due to {:?}", good_branch_match); if level == log::Level::Error { @@ -157,7 +157,10 @@ pub fn verify_if_behind( let branch = crate::ops::git::current_branch(path)?; crate::ops::git::fetch(path, git_remote, &branch)?; if crate::ops::git::is_behind_remote(path, git_remote, &branch)? { - log::log!(level, "{} is behind {}/{}", branch, git_remote, branch); + let _ = crate::ops::shell::log( + level, + format!("{} is behind {}/{}", branch, git_remote, branch), + ); if level == log::Level::Error { success = false; if !dry_run { @@ -181,12 +184,12 @@ pub fn verify_monotonically_increasing( if let Some(version) = pkg.planned_version.as_ref() { if version.full_version < pkg.initial_version.full_version { let crate_name = pkg.meta.name.as_str(); - log::log!( + let _ = crate::ops::shell::log( level, - "Cannot downgrade {} from {} to {}", - crate_name, - version.full_version, - pkg.initial_version.full_version + format!( + "Cannot downgrade {} from {} to {}", + crate_name, version.full_version, pkg.initial_version.full_version + ), ); downgrades_present = true; } @@ -229,20 +232,24 @@ pub fn verify_rate_limit( if 5 < new { // "The rate limit for creating new crates is 1 crate every 10 minutes, with a burst of 5 crates." success = false; - log::log!( + let _ = crate::ops::shell::log( level, - "Attempting to publish {} new crates which is above the crates.io rate limit", - new + format!( + "Attempting to publish {} new crates which is above the crates.io rate limit", + new + ), ); } if 30 < existing { // "The rate limit for new versions of existing crates is 1 per minute, with a burst of 30 crates, so when releasing new versions of these crates, you shouldn't hit the limit." success = false; - log::log!( + let _ = crate::ops::shell::log( level, - "Attempting to publish {} existing crates which is above the crates.io rate limit", - existing + format!( + "Attempting to publish {} existing crates which is above the crates.io rate limit", + existing + ), ); } @@ -299,11 +306,13 @@ pub fn verify_metadata( } if !missing.is_empty() { - log::log!( + let _ = crate::ops::shell::log( level, - "{} is missing the following fields:\n {}", - pkg.meta.name, - missing.join("\n ") + format!( + "{} is missing the following fields:\n {}", + pkg.meta.name, + missing.join("\n ") + ), ); success = false; } @@ -355,12 +364,10 @@ pub fn warn_changed( // Lock file changes don't invalidate dependents, which is why this check is // after the transitive check, so that can invalidate dependents } else { - log::warn!( + let _ = crate::ops::shell::warn(format!( "Updating {} to {} despite no changes made since tag {}", - crate_name, - version.full_version_string, - prior_tag_name - ); + crate_name, version.full_version_string, prior_tag_name + )); } } else { log::debug!( @@ -396,12 +403,12 @@ pub fn find_shared_versions( std::collections::hash_map::Entry::Occupied(existing) => { if version.bare_version != existing.get().bare_version { is_shared = false; - log::error!( + let _ = crate::ops::shell::error(format!( "{} has version {}, should be {}", pkg.meta.name, version.bare_version_string, existing.get().bare_version_string - ); + )); } } std::collections::hash_map::Entry::Vacant(vacant) => { @@ -410,7 +417,7 @@ pub fn find_shared_versions( } } if !is_shared { - log::error!("Crate versions deviated, aborting"); + let _ = crate::ops::shell::error(format!("Crate versions deviated, aborting")); return Err(101.into()); } @@ -431,7 +438,7 @@ pub fn consolidate_commits( if consolidate_commits.is_none() { consolidate_commits = current; } else if consolidate_commits != current { - log::error!("Inconsistent `consolidate-commits` setting"); + let _ = crate::ops::shell::error(format!("Inconsistent `consolidate-commits` setting")); return Err(101.into()); } } @@ -481,10 +488,13 @@ pub fn confirm( pub fn finish(failed: bool, dry_run: bool) -> Result<(), crate::error::CliError> { if dry_run { if failed { - log::error!("Dry-run failed, resolve the above errors and try again."); + let _ = + crate::ops::shell::error("Dry-run failed, resolve the above errors and try again."); Err(101.into()) } else { - log::warn!("Ran a `dry-run`, re-run with `--execute` if all looked good."); + let _ = crate::ops::shell::warn( + "Ran a `dry-run`, re-run with `--execute` if all looked good.", + ); Ok(()) } } else { diff --git a/src/steps/owner.rs b/src/steps/owner.rs index e1caa1f95..9ec60a316 100644 --- a/src/steps/owner.rs +++ b/src/steps/owner.rs @@ -69,7 +69,7 @@ impl OwnerStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } diff --git a/src/steps/publish.rs b/src/steps/publish.rs index f7728ca0a..a7e34bbcb 100644 --- a/src/steps/publish.rs +++ b/src/steps/publish.rs @@ -75,11 +75,10 @@ impl PublishStep { let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version); if crate::ops::cargo::is_published(&index, crate_name, &version.full_version_string) { - log::warn!( + let _ = crate::ops::shell::warn(format!( "Disabled due to previous publish ({}), skipping {}", - version.full_version_string, - crate_name - ); + version.full_version_string, crate_name + )); pkg.config.publish = Some(false); pkg.config.release = Some(false); } @@ -91,7 +90,7 @@ impl PublishStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } @@ -154,7 +153,7 @@ pub fn publish( } let crate_name = pkg.meta.name.as_str(); - log::info!("Publishing {}", crate_name); + let _ = crate::ops::shell::status("Publishing", crate_name); let verify = if !pkg.config.verify() { false @@ -203,7 +202,7 @@ pub fn publish( .parse() .unwrap_or(0); if 0 < publish_grace_sleep { - log::info!( + log::debug!( "Waiting an additional {} seconds for crates.io to update its indices...", publish_grace_sleep ); diff --git a/src/steps/push.rs b/src/steps/push.rs index ab5e4ce1e..a1dc0f847 100644 --- a/src/steps/push.rs +++ b/src/steps/push.rs @@ -76,7 +76,7 @@ impl PushStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } @@ -157,7 +157,10 @@ pub fn push( if !shared_refs.is_empty() { let mut shared_refs = shared_refs.into_iter().collect::>(); shared_refs.sort_unstable(); - log::info!("Pushing {} to {}", shared_refs.join(", "), git_remote); + let _ = crate::ops::shell::status( + "Pushing", + format!("Pushing {} to {}", shared_refs.join(", "), git_remote), + ); if !git::push( ws_meta.workspace_root.as_std_path(), git_remote, diff --git a/src/steps/release.rs b/src/steps/release.rs index d98717cc9..23a5843aa 100644 --- a/src/steps/release.rs +++ b/src/steps/release.rs @@ -102,18 +102,16 @@ impl ReleaseStep { crate::steps::version::changed_since(&ws_meta, pkg, prior_tag_name) { if !changed.is_empty() { - log::warn!( + let _ = crate::ops::shell::warn(format!( "Disabled by user, skipping {} which has files changed since {}: {:#?}", - crate_name, - prior_tag_name, - changed - ); + crate_name, prior_tag_name, changed + )); } else if lock_changed { - log::warn!( - "Disabled by user, skipping {} despite lock file being changed since {}", - crate_name, - prior_tag_name - ); + let _ = crate::ops::shell::warn(format!( + "Disabled by user, skipping {} despite lock file being changed since {}", + crate_name, + prior_tag_name + )); } else { log::trace!( "Disabled by user, skipping {} (no changes since {})", @@ -147,11 +145,10 @@ impl ReleaseStep { let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version); let crate_name = pkg.meta.name.as_str(); if !cargo::is_published(&index, crate_name, &version.full_version_string) { - log::warn!( + let _ = crate::ops::shell::warn(format!( "Disabled by user, skipping {} v{} despite being unpublished", - crate_name, - version.full_version_string, - ); + crate_name, version.full_version_string, + )); } } } @@ -161,7 +158,7 @@ impl ReleaseStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } @@ -191,11 +188,10 @@ impl ReleaseStep { let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version); let crate_name = pkg.meta.name.as_str(); if cargo::is_published(&index, crate_name, &version.full_version_string) { - log::error!( + let _ = crate::ops::shell::error(format!( "{} {} is already published", - crate_name, - version.full_version_string - ); + crate_name, version.full_version_string + )); double_publish = true; } } @@ -253,10 +249,14 @@ impl ReleaseStep { for pkg in &selected_pkgs { if let Some(version) = pkg.planned_version.as_ref() { let crate_name = pkg.meta.name.as_str(); - log::info!( - "Update {} to version {}", - crate_name, - version.full_version_string + let _ = crate::ops::shell::status( + "Upgrading", + format!( + "{} from {} to {}", + crate_name, + pkg.initial_version.full_version_string, + version.full_version_string + ), ); cargo::set_package_version( &pkg.manifest_path, diff --git a/src/steps/replace.rs b/src/steps/replace.rs index ce79ab785..8d2a71604 100644 --- a/src/steps/replace.rs +++ b/src/steps/replace.rs @@ -92,7 +92,7 @@ impl ReplaceStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } diff --git a/src/steps/tag.rs b/src/steps/tag.rs index 7cb48171e..44f40c22e 100644 --- a/src/steps/tag.rs +++ b/src/steps/tag.rs @@ -77,11 +77,10 @@ impl TagStep { if let Some(tag_name) = pkg.planned_tag.as_ref() { if crate::ops::git::tag_exists(ws_meta.workspace_root.as_std_path(), tag_name)? { let crate_name = pkg.meta.name.as_str(); - log::warn!( + let _ = crate::ops::shell::warn(format!( "Disabled due to existing tag ({}), skipping {}", - tag_name, - crate_name - ); + tag_name, crate_name + )); pkg.planned_tag = None; pkg.config.tag = Some(false); pkg.config.release = Some(false); @@ -94,7 +93,7 @@ impl TagStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } diff --git a/src/steps/version.rs b/src/steps/version.rs index 332700e4b..5fc05be11 100644 --- a/src/steps/version.rs +++ b/src/steps/version.rs @@ -87,7 +87,7 @@ impl VersionStep { .map(|(_, pkg)| pkg) .partition(|p| p.config.release()); if selected_pkgs.is_empty() { - log::info!("No packages selected."); + let _ = crate::ops::shell::error("No packages selected"); return Err(2.into()); } @@ -206,9 +206,12 @@ pub fn update_versions( .find_map(|p| p.planned_version.clone()); if let Some(workspace_version) = &workspace_version { - log::info!( - "Upgrading workspace to version {}", - workspace_version.full_version_string + let _ = crate::ops::shell::status( + "Upgrading", + format!( + "workspace to version {}", + workspace_version.full_version_string + ), ); let workspace_path = ws_meta.workspace_root.as_std_path().join("Cargo.toml"); crate::ops::cargo::set_workspace_version( @@ -239,19 +242,25 @@ pub fn update_versions( if let Some(version) = planned_version { if is_inherited { let crate_name = pkg.meta.name.as_str(); - log::info!( - "Upgrading {} from {} to {} (inherited from workspace)", - crate_name, - pkg.initial_version.full_version_string, - version.full_version_string + let _ = crate::ops::shell::status( + "Upgrading", + format!( + "{} from {} to {} (inherited from workspace)", + crate_name, + pkg.initial_version.full_version_string, + version.full_version_string + ), ); } else { let crate_name = pkg.meta.name.as_str(); - log::info!( - "Upgrading {} from {} to {}", - crate_name, - pkg.initial_version.full_version_string, - version.full_version_string + let _ = crate::ops::shell::status( + "Upgrading", + format!( + "{} from {} to {}", + crate_name, + pkg.initial_version.full_version_string, + version.full_version_string + ), ); crate::ops::cargo::set_package_version( &pkg.manifest_path, diff --git a/tests/version/downgrade_error/stderr.log b/tests/version/downgrade_error/stderr.log index ffc12c23d..5261aec9e 100644 --- a/tests/version/downgrade_error/stderr.log +++ b/tests/version/downgrade_error/stderr.log @@ -1 +1 @@ -[ERROR] Cannot downgrade sample from 0.0.1 to 0.1.0 +error: Cannot downgrade sample from 0.0.1 to 0.1.0 diff --git a/tests/version/dry_run/stderr.log b/tests/version/dry_run/stderr.log index fcf0c4631..857e4ece7 100644 --- a/tests/version/dry_run/stderr.log +++ b/tests/version/dry_run/stderr.log @@ -1,3 +1,3 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading sample from 0.1.0 to 2.0.0 -[WARN ] Ran a `dry-run`, re-run with `--execute` if all looked good. +warning: Push target `origin/master` doesn't exist + Upgrading sample from 0.1.0 to 2.0.0 +warning: Ran a `dry-run`, re-run with `--execute` if all looked good. diff --git a/tests/version/ignore_dependent/stderr.log b/tests/version/ignore_dependent/stderr.log index a23eff02a..b78e267af 100644 --- a/tests/version/ignore_dependent/stderr.log +++ b/tests/version/ignore_dependent/stderr.log @@ -1,2 +1,2 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 diff --git a/tests/version/set_absolute_version/stderr.log b/tests/version/set_absolute_version/stderr.log index a1c10e617..3f0649b3f 100644 --- a/tests/version/set_absolute_version/stderr.log +++ b/tests/version/set_absolute_version/stderr.log @@ -1,2 +1,2 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading sample from 0.1.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading sample from 0.1.0 to 2.0.0 diff --git a/tests/version/set_absolute_workspace_version/stderr.log b/tests/version/set_absolute_workspace_version/stderr.log index 5034dc7ab..50292c858 100644 --- a/tests/version/set_absolute_workspace_version/stderr.log +++ b/tests/version/set_absolute_workspace_version/stderr.log @@ -1,5 +1,5 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading workspace to version 2.0.0 -[INFO ] Upgrading inherit_ws_version from 0.2.0 to 2.0.0 (inherited from workspace) -[INFO ] Updating workspace's dependency from 0.2 to 2.0 -[INFO ] Updating with_direct_dep's dependency from 0.2 to 2.0 +warning: Push target `origin/master` doesn't exist + Upgrading workspace to version 2.0.0 + Upgrading inherit_ws_version from 0.2.0 to 2.0.0 (inherited from workspace) + Updating workspace's dependency from 0.2 to 2.0 + Updating with_direct_dep's dependency from 0.2 to 2.0 diff --git a/tests/version/set_relative_version/stderr.log b/tests/version/set_relative_version/stderr.log index 25ab6b2aa..84129386f 100644 --- a/tests/version/set_relative_version/stderr.log +++ b/tests/version/set_relative_version/stderr.log @@ -1,2 +1,2 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading sample from 0.1.0 to 1.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading sample from 0.1.0 to 1.0.0 diff --git a/tests/version/set_relative_workspace_version/stderr.log b/tests/version/set_relative_workspace_version/stderr.log index 05b2fc3ca..c695f28e3 100644 --- a/tests/version/set_relative_workspace_version/stderr.log +++ b/tests/version/set_relative_workspace_version/stderr.log @@ -1,5 +1,5 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading workspace to version 1.0.0 -[INFO ] Upgrading inherit_ws_version from 0.2.0 to 1.0.0 (inherited from workspace) -[INFO ] Updating workspace's dependency from 0.2 to 1.0 -[INFO ] Updating with_direct_dep's dependency from 0.2 to 1.0 +warning: Push target `origin/master` doesn't exist + Upgrading workspace to version 1.0.0 + Upgrading inherit_ws_version from 0.2.0 to 1.0.0 (inherited from workspace) + Updating workspace's dependency from 0.2 to 1.0 + Updating with_direct_dep's dependency from 0.2 to 1.0 diff --git a/tests/version/upgrade_compatible_dependency/stderr.log b/tests/version/upgrade_compatible_dependency/stderr.log index 6dc9e8bca..f32af8f55 100644 --- a/tests/version/upgrade_compatible_dependency/stderr.log +++ b/tests/version/upgrade_compatible_dependency/stderr.log @@ -1,3 +1,3 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 0.4.5 -[INFO ] Updating cargo-list-test-fixture's dependency from 0.4.3 to 0.4.5 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 0.4.5 + Updating cargo-list-test-fixture's dependency from 0.4.3 to 0.4.5 diff --git a/tests/version/upgrade_incompatible_dependency/stderr.log b/tests/version/upgrade_incompatible_dependency/stderr.log index df8fe0796..a504b7c79 100644 --- a/tests/version/upgrade_incompatible_dependency/stderr.log +++ b/tests/version/upgrade_incompatible_dependency/stderr.log @@ -1,3 +1,3 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 -[INFO ] Updating cargo-list-test-fixture's dependency from 0.4.3 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 + Updating cargo-list-test-fixture's dependency from 0.4.3 to 2.0.0 diff --git a/tests/version/upgrade_workspace/stderr.log b/tests/version/upgrade_workspace/stderr.log index 009255e61..4f70a63c8 100644 --- a/tests/version/upgrade_workspace/stderr.log +++ b/tests/version/upgrade_workspace/stderr.log @@ -1,4 +1,4 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 -[INFO ] Updating cargo-list-test-fixture's dependency from 0.4.3 to 2.0.0 -[INFO ] Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 + Updating cargo-list-test-fixture's dependency from 0.4.3 to 2.0.0 + Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 diff --git a/tests/version/virtual_workspace_deps/stderr.log b/tests/version/virtual_workspace_deps/stderr.log index d14f3d2ae..ec7d1d251 100644 --- a/tests/version/virtual_workspace_deps/stderr.log +++ b/tests/version/virtual_workspace_deps/stderr.log @@ -1,4 +1,4 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 -[INFO ] Updating workspace's dependency from 0.4.3 to 2.0.0 -[INFO ] Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 + Updating workspace's dependency from 0.4.3 to 2.0.0 + Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 diff --git a/tests/version/workspace_deps/stderr.log b/tests/version/workspace_deps/stderr.log index d14f3d2ae..ec7d1d251 100644 --- a/tests/version/workspace_deps/stderr.log +++ b/tests/version/workspace_deps/stderr.log @@ -1,4 +1,4 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 -[INFO ] Updating workspace's dependency from 0.4.3 to 2.0.0 -[INFO ] Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading cargo-list-test-fixture-dependency from 0.4.3 to 2.0.0 + Updating workspace's dependency from 0.4.3 to 2.0.0 + Upgrading cargo-list-test-fixture from 0.0.0 to 2.0.0 diff --git a/tests/version/workspace_version_exclude/stderr.log b/tests/version/workspace_version_exclude/stderr.log index 8ac31c48f..f899f7cb2 100644 --- a/tests/version/workspace_version_exclude/stderr.log +++ b/tests/version/workspace_version_exclude/stderr.log @@ -1,8 +1,8 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading workspace to version 2.0.0 -[INFO ] Upgrading inherits-version from 0.1.0 to 2.0.0 (inherited from workspace) -[INFO ] Updating workspace's dependency from 0.1.0 to 2.0.0 -[INFO ] Upgrading independent-version from 0.1.0 to 2.0.0 -[INFO ] Updating workspace's dependency from 0.1.0 to 2.0.0 -[INFO ] Updating workspace's dependency from 0.1.0 to 2.0.0 -[INFO ] Upgrading root from 0.1.0 to 2.0.0 (inherited from workspace) +warning: Push target `origin/master` doesn't exist + Upgrading workspace to version 2.0.0 + Upgrading inherits-version from 0.1.0 to 2.0.0 (inherited from workspace) + Updating workspace's dependency from 0.1.0 to 2.0.0 + Upgrading independent-version from 0.1.0 to 2.0.0 + Updating workspace's dependency from 0.1.0 to 2.0.0 + Updating workspace's dependency from 0.1.0 to 2.0.0 + Upgrading root from 0.1.0 to 2.0.0 (inherited from workspace) diff --git a/tests/version/workspace_version_subset/stderr.log b/tests/version/workspace_version_subset/stderr.log index e208dfdfd..35f287ab9 100644 --- a/tests/version/workspace_version_subset/stderr.log +++ b/tests/version/workspace_version_subset/stderr.log @@ -1,5 +1,5 @@ -[WARN ] Push target `origin/master` doesn't exist -[INFO ] Upgrading workspace to version 2.0.0 -[INFO ] Upgrading root from 0.1.0 to 2.0.0 (inherited from workspace) -[INFO ] Upgrading inherits-version from 0.1.0 to 2.0.0 (inherited from workspace) -[INFO ] Updating workspace's dependency from 0.1.0 to 2.0.0 +warning: Push target `origin/master` doesn't exist + Upgrading workspace to version 2.0.0 + Upgrading root from 0.1.0 to 2.0.0 (inherited from workspace) + Upgrading inherits-version from 0.1.0 to 2.0.0 (inherited from workspace) + Updating workspace's dependency from 0.1.0 to 2.0.0