Skip to content

Commit

Permalink
fix(cli): Match cargo in casing
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 20, 2022
1 parent 151d39b commit d398ae5
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 95 deletions.
26 changes: 13 additions & 13 deletions src/ops/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn package_content(manifest_path: &Path) -> CargoResult<Vec<std::path::PathB
} else {
let error = String::from_utf8_lossy(&output.stderr);
Err(anyhow::format_err!(
"Failed to get package content for {}: {}",
"failed to get package content for {}: {}",
manifest_path.display(),
error
))
Expand Down Expand Up @@ -122,12 +122,12 @@ pub fn wait_for_publish(
let mut logged = false;
loop {
if let Err(e) = index.update() {
log::debug!("Crate index update failed with {}", e);
log::debug!("crate index update failed with {}", e);
}
if is_published(index, name, version) {
break;
} else if timeout < now.elapsed() {
anyhow::bail!("Timeout waiting for crate to be published");
anyhow::bail!("timeout waiting for crate to be published");
}

if !logged {
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn set_workspace_version(
"updated",
0,
);
log::debug!("Change:\n{}", itertools::join(diff.into_iter(), ""));
log::debug!("change:\n{}", itertools::join(diff.into_iter(), ""));
}
} else {
atomic_write(manifest_path, &manifest)?;
Expand Down Expand Up @@ -207,12 +207,12 @@ pub fn ensure_owners(
let output = cmd.output()?;
if !output.status.success() {
anyhow::bail!(
"Failed talking to registry about crate owners: {}",
"failed talking to registry about crate owners: {}",
String::from_utf8_lossy(&output.stderr)
);
}
let raw = String::from_utf8(output.stdout)
.map_err(|_| anyhow::format_err!("Unrecognized response from registry"))?;
.map_err(|_| anyhow::format_err!("unrecognized response from registry"))?;

let mut current = std::collections::BTreeSet::new();
// HACK: No programmatic CLI access and don't want to link against `cargo` (yet), so parsing
Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn ensure_owners(
// 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
let _ = crate::ops::shell::warn(format!(
"Failed to set owners for {}: {}",
"failed to set owners for {}: {}",
name,
String::from_utf8_lossy(&output.stderr)
));
Expand All @@ -261,7 +261,7 @@ pub fn ensure_owners(

let extra = current.difference(&expected).copied().collect::<Vec<_>>();
if !extra.is_empty() {
log::debug!("Extra owners for {}: {}", name, extra.join(", "));
log::debug!("extra owners for {}: {}", name, extra.join(", "));
}

Ok(())
Expand Down Expand Up @@ -290,7 +290,7 @@ pub fn set_package_version(manifest_path: &Path, version: &str, dry_run: bool) -
"updated",
0,
);
log::debug!("Change:\n{}", itertools::join(diff.into_iter(), ""));
log::debug!("change:\n{}", itertools::join(diff.into_iter(), ""));
}
} else {
atomic_write(manifest_path, &manifest)?;
Expand Down Expand Up @@ -339,7 +339,7 @@ pub fn upgrade_dependency_req(
"updated",
0,
);
log::debug!("Change:\n{}", itertools::join(diff.into_iter(), ""));
log::debug!("change:\n{}", itertools::join(diff.into_iter(), ""));
} else {
atomic_write(manifest_path, &manifest)?;
}
Expand Down Expand Up @@ -414,20 +414,20 @@ fn upgrade_req(
let version_value = if let Some(version_value) = dep_item.get_mut("version") {
version_value
} else {
log::debug!("Not updating path-only dependency on {}", name);
log::debug!("not updating path-only dependency on {}", name);
return false;
};

let existing_req_str = if let Some(existing_req) = version_value.as_str() {
existing_req
} else {
log::debug!("Unsupported dependency {}", name);
log::debug!("unsupported dependency {}", name);
return false;
};
let existing_req = if let Ok(existing_req) = semver::VersionReq::parse(existing_req_str) {
existing_req
} else {
log::debug!("Unsupported dependency req {}={}", name, existing_req_str);
log::debug!("unsupported dependency req {}={}", name, existing_req_str);
return false;
};
let new_req = match upgrade {
Expand Down
8 changes: 4 additions & 4 deletions src/ops/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn is_behind_remote(dir: &Path, remote: &str, branch: &str) -> CargoResult<b
}
Err(err) => {
let _ =
crate::ops::shell::warn(format!("Push target `{}` doesn't exist", remote_branch));
log::trace!("Error {}", err);
crate::ops::shell::warn(format!("push target `{}` doesn't exist", remote_branch));
log::trace!("error {}", err);
false
}
};
Expand All @@ -65,8 +65,8 @@ pub fn is_local_unchanged(dir: &Path, remote: &str, branch: &str) -> CargoResult
}
Err(err) => {
let _ =
crate::ops::shell::warn(format!("Push target `{}` doesn't exist", remote_branch));
log::trace!("Error {}", err);
crate::ops::shell::warn(format!("push target `{}` doesn't exist", remote_branch));
log::trace!("error {}", err);
false
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/ops/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ pub fn do_file_replacements(
for (path, replaces) in by_file.into_iter() {
let file = cwd.join(&path);
if !file.exists() {
anyhow::bail!("Unable to find file {} to perform replace", file.display());
anyhow::bail!("unable to find file {} to perform replace", file.display());
}
let data = std::fs::read_to_string(&file)?;
let mut replaced = data.clone();

for replace in replaces {
if prerelease && !replace.prerelease {
log::debug!("Pre-release, not replacing {}", replace.search);
log::debug!("pre-release, not replacing {}", replace.search);
continue;
}

Expand All @@ -100,14 +100,14 @@ pub fn do_file_replacements(
let actual = r.find_iter(&replaced).count();
if actual < min {
anyhow::bail!(
"For `{}`, at least {} replacements expected, found {}",
"for `{}`, at least {} replacements expected, found {}",
pattern,
min,
actual
);
} else if max < actual {
anyhow::bail!(
"For `{}`, at most {} replacements expected, found {}",
"for `{}`, at most {} replacements expected, found {}",
pattern,
max,
actual
Expand Down
12 changes: 6 additions & 6 deletions src/ops/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl VersionExt for semver::Version {
if let Some((pre_ext, pre_ext_ver)) = prerelease_id_version(self)? {
if pre_ext == VERSION_BETA || pre_ext == VERSION_RC {
Err(anyhow::format_err!(
"Unsupported release level {}, only major, minor, and patch are supported",
"unsupported release level {}, only major, minor, and patch are supported",
VERSION_ALPHA
))
} else {
Expand All @@ -83,7 +83,7 @@ impl VersionExt for semver::Version {
if let Some((pre_ext, pre_ext_ver)) = prerelease_id_version(self)? {
if pre_ext == VERSION_RC {
Err(anyhow::format_err!(
"Unsupported release level {}, only major, minor, and patch are supported",
"unsupported release level {}, only major, minor, and patch are supported",
VERSION_BETA
))
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ fn prerelease_id_version(version: &semver::Version) -> CargoResult<Option<(Strin
if let Some((alpha, numeric)) = version.pre.as_str().split_once('.') {
let alpha = alpha.to_owned();
let numeric = u64::from_str(numeric)
.map_err(|_| anyhow::format_err!("Pre-release `{}` version scheme is not supported by cargo-release. Use format like `pre`, `dev`, or `alpha.1` for prerelease", version.pre))?;
.map_err(|_| anyhow::format_err!("pre-release `{}` version scheme is not supported by cargo-release. Use format like `pre`, `dev`, or `alpha.1` for prerelease", version.pre))?;
Ok(Some((alpha, Some(numeric))))
} else {
Ok(Some((version.pre.as_str().to_owned(), None)))
Expand Down Expand Up @@ -201,14 +201,14 @@ fn set_comparator(
}
semver::Op::Exact => Ok(assign_partial_req(version, pred)),
semver::Op::Greater | semver::Op::GreaterEq | semver::Op::Less | semver::Op::LessEq => Err(
anyhow::format_err!("Support for modifying {} is currently unsupported", pred),
anyhow::format_err!("support for modifying {} is currently unsupported", pred),
),
semver::Op::Tilde => Ok(assign_partial_req(version, pred)),
semver::Op::Caret => Ok(assign_partial_req(version, pred)),
_ => {
log::debug!("New predicate added");
log::debug!("new predicate added");
Err(anyhow::format_err!(
"Support for modifying {} is currently unsupported",
"support for modifying {} is currently unsupported",
pred
))
}
Expand Down
2 changes: 1 addition & 1 deletion src/steps/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
let _ = crate::ops::shell::error("Nothing to commit");
let _ = crate::ops::shell::error("nothing to commit");
return Err(2.into());
}

Expand Down
2 changes: 1 addition & 1 deletion src/steps/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct ConfigStep {

impl ConfigStep {
pub fn run(&self) -> Result<(), CliError> {
log::trace!("Initializing");
log::trace!("initializing");
let ws_meta = self
.manifest
.metadata()
Expand Down
8 changes: 4 additions & 4 deletions src/steps/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl HookStep {
&version.full_version_string,
) {
log::debug!(
"Enabled {}, v{} is unpublished",
"enabled {}, v{} is unpublished",
crate_name,
version.full_version_string
);
Expand All @@ -96,7 +96,7 @@ impl HookStep {
.map(|(_, pkg)| pkg)
.partition(|p| p.config.release());
if selected_pkgs.is_empty() {
let _ = crate::ops::shell::error("No packages selected");
let _ = crate::ops::shell::error("no packages selected");
return Err(2.into());
}

Expand Down Expand Up @@ -175,7 +175,7 @@ pub fn hook(
.into_iter()
.map(|arg| template.render(arg))
.collect::<Vec<_>>();
log::debug!("Calling pre-release hook: {:?}", pre_rel_hook);
log::debug!("calling pre-release hook: {:?}", pre_rel_hook);
let envs = maplit::btreemap! {
OsStr::new("PREV_VERSION") => prev_version_var.as_ref(),
OsStr::new("PREV_METADATA") => prev_metadata_var.as_ref(),
Expand All @@ -190,7 +190,7 @@ pub fn hook(
// so here we set dry_run=false and always execute the command.
if !cmd::call_with_env(pre_rel_hook, envs, cwd, false)? {
let _ = crate::ops::shell::error(format!(
"Release of {} aborted by non-zero return of prerelease hook.",
"release of {} aborted by non-zero return of prerelease hook.",
crate_name
));
return Err(101.into());
Expand Down
33 changes: 16 additions & 17 deletions src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn verify_git_is_clean(
let _ = crate::ops::shell::log(
level,
format!(
"Uncommitted changes detected, please resolve before release:\n {}",
"uncommitted changes detected, please resolve before release:\n {}",
dirty.join("\n ")
),
);
Expand Down Expand Up @@ -56,7 +56,7 @@ pub fn verify_tags_missing(
let crate_name = pkg.meta.name.as_str();
let _ = crate::ops::shell::log(
level,
format!("Tag `{}` already exists (for `{}`)", tag_name, crate_name),
format!("tag `{}` already exists (for `{}`)", tag_name, crate_name),
);
tag_exists = true;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn verify_tags_exist(
let crate_name = pkg.meta.name.as_str();
let _ = crate::ops::shell::log(
level,
format!("Tag `{}` doesn't exist (for `{}`)", tag_name, crate_name),
format!("tag `{}` doesn't exist (for `{}`)", tag_name, crate_name),
);
tag_missing = true;
}
Expand Down Expand Up @@ -128,12 +128,12 @@ pub fn verify_git_branch(
let _ = crate::ops::shell::log(
level,
format!(
"Cannot release from branch {:?}, instead switch to {:?}",
"cannot release from branch {:?}, instead switch to {:?}",
branch,
ws_config.allow_branch().join(", ")
),
);
log::trace!("Due to {:?}", good_branch_match);
log::trace!("due to {:?}", good_branch_match);
if level == log::Level::Error {
success = false;
if !dry_run {
Expand Down Expand Up @@ -187,7 +187,7 @@ pub fn verify_monotonically_increasing(
let _ = crate::ops::shell::log(
level,
format!(
"Cannot downgrade {} from {} to {}",
"cannot downgrade {} from {} to {}",
crate_name, version.full_version, pkg.initial_version.full_version
),
);
Expand Down Expand Up @@ -235,7 +235,7 @@ pub fn verify_rate_limit(
let _ = crate::ops::shell::log(
level,
format!(
"Attempting to publish {} new crates which is above the crates.io rate limit",
"attempting to publish {} new crates which is above the crates.io rate limit",
new
),
);
Expand All @@ -247,7 +247,7 @@ pub fn verify_rate_limit(
let _ = crate::ops::shell::log(
level,
format!(
"Attempting to publish {} existing crates which is above the crates.io rate limit",
"attempting to publish {} existing crates which is above the crates.io rate limit",
existing
),
);
Expand Down Expand Up @@ -365,20 +365,20 @@ pub fn warn_changed(
// after the transitive check, so that can invalidate dependents
} else {
let _ = crate::ops::shell::warn(format!(
"Updating {} to {} despite no changes made since tag {}",
"updating {} to {} despite no changes made since tag {}",
crate_name, version.full_version_string, prior_tag_name
));
}
} else {
log::debug!(
"Cannot detect changes for {} because tag {} is missing. Try setting `--prev-tag-name <TAG>`.",
"cannot detect changes for {} because tag {} is missing. Try setting `--prev-tag-name <TAG>`.",
crate_name,
prior_tag_name
);
}
} else {
log::debug!(
"Cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
"cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
crate_name,
);
}
Expand Down Expand Up @@ -417,7 +417,7 @@ pub fn find_shared_versions(
}
}
if !is_shared {
let _ = crate::ops::shell::error(format!("Crate versions deviated, aborting"));
let _ = crate::ops::shell::error(format!("crate versions deviated, aborting"));
return Err(101.into());
}

Expand All @@ -438,7 +438,7 @@ pub fn consolidate_commits(
if consolidate_commits.is_none() {
consolidate_commits = current;
} else if consolidate_commits != current {
let _ = crate::ops::shell::error(format!("Inconsistent `consolidate-commits` setting"));
let _ = crate::ops::shell::error(format!("inconsistent `consolidate-commits` setting"));
return Err(101.into());
}
}
Expand Down Expand Up @@ -489,12 +489,11 @@ pub fn finish(failed: bool, dry_run: bool) -> Result<(), crate::error::CliError>
if dry_run {
if failed {
let _ =
crate::ops::shell::error("Dry-run failed, resolve the above errors and try again.");
crate::ops::shell::error("dry-run failed, resolve the above errors and try again.");
Err(101.into())
} else {
let _ = crate::ops::shell::warn(
"Ran a `dry-run`, re-run with `--execute` if all looked good.",
);
let _ =
crate::ops::shell::warn("aborting release due to dry run; re-run with `--execute`");
Ok(())
}
} else {
Expand Down
Loading

0 comments on commit d398ae5

Please sign in to comment.