Skip to content

Commit

Permalink
feat(config): Add positive config values
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 8, 2021
1 parent 5aabba9 commit 9717045
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
12 changes: 6 additions & 6 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ Configuration is read from the following (in precedence order)
| `sign-tag` | `--sign-tag` | bool | Use GPG to sign git tag generated by cargo-release. |
| `push-remote` | `--push-remote` | string | Default git remote to push |
| `registry` | `--registry` | string | Cargo registry name to publish to (default uses Rust's default, which goes to `crates.io`) |
| `disable-release` | `--exclude` | bool | Skip the entire release process (usually for internal crates in a workspace) |
| `disable-push` | `--no-push` | bool | Don't do git push |
| `release` | `--exclude` | bool | Skip the entire release process (usually for internal crates in a workspace) |
| `push` | `--no-push` | bool | Don't do git push |
| `push-options` | \- | list of strings | Flags to send to the server when doing a `git push` |
| `disable-tag` | `--no-tag` | bool | Don't do git tag |
| `disable-publish` | `--no-publish` | bool | Don't do cargo publish right now, see [manifest `publish` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish--field-optional) to permanently disable publish. |
| `no-verify` | `--no-verify` | bool | Don't verify the contents by building them |
| `tag` | `--no-tag` | bool | Don't do git tag |
| `publish` | `--no-publish` | bool | Don't do cargo publish right now, see [manifest `publish` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish--field-optional) to permanently disable publish. |
| `verify` | `--no-verify` | bool | Don't verify the contents by building them |
| `shared-version` | \- | bool | Ensure all crates with `shared_version` are the same version |
| `consolidate-commits` | \- | bool | When releasing a workspace, use a single commit for the pre-release version bump and a single commit for the post-release version bump. |
| `consolidate-pushes` | \- | bool | When releasing a workspace, use do a single push across all crates in a workspace. |
Expand All @@ -67,7 +67,7 @@ Configuration is read from the following (in precedence order)
| `tag-prefix` | `--tag-prefix` | string | Prefix of git tag, note that this will override default prefix based on crate name. |
| `tag-name` | `--tag-name` | string | The name of the git tag. The placeholder `{{prefix}}` (the tag prefix) is supported in addition to the global placeholders mentioned below. |
| `dev-version-ext` | `--dev-version-ext` | string | Pre-release extension to use on the next development version. |
| `no-dev-version` | `--no-dev-version` | bool | Disable version bump after release. |
| `dev-version` | `--no-dev-version` | bool | Disable version bump after release. |
| `pre-release-replacements` | \- | array of tables (see below) | Specify files that cargo-release will search and replace with new version for the release commit |
| `post-release-replacements` | \- | array of tables (see below) | Specify files that cargo-release will search and replace with new version for the post-release commit (the one starting development) |
| `pre-release-hook` | \- | list of arguments | Provide a command to run before `cargo-release` commits version change. If the return code of hook command is greater than 0, the release process will be aborted. |
Expand Down
10 changes: 5 additions & 5 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ impl ConfigArgs {
sign_tag: resolve_bool_arg(self.sign_tag, self.no_sign_tag).or_else(|| self.sign()),
push_remote: self.push_remote.clone(),
registry: self.registry.clone(),
disable_publish: resolve_bool_arg(self.no_publish, self.publish),
no_verify: resolve_bool_arg(self.no_verify, self.verify),
disable_push: resolve_bool_arg(self.no_push, self.push),
publish: resolve_bool_arg(self.publish, self.no_publish),
verify: resolve_bool_arg(self.verify, self.no_verify),
push: resolve_bool_arg(self.push, self.no_push),
dev_version_ext: self.dev_version_ext.clone(),
no_dev_version: resolve_bool_arg(self.no_dev_version, self.dev_version),
dev_version: resolve_bool_arg(self.dev_version, self.no_dev_version),
tag_prefix: self.tag_prefix.clone(),
tag_name: self.tag_name.clone(),
disable_tag: resolve_bool_arg(self.no_tag, self.tag),
tag: resolve_bool_arg(self.tag, self.no_tag),
enable_features: (!self.features.is_empty()).then(|| self.features.clone()),
enable_all_features: self.all_features.then(|| true),
dependent_version: self.dependent_version,
Expand Down
60 changes: 42 additions & 18 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ pub struct Config {
pub sign_tag: Option<bool>,
pub push_remote: Option<String>,
pub registry: Option<String>,
pub release: Option<bool>,
pub disable_release: Option<bool>,
pub publish: Option<bool>,
pub disable_publish: Option<bool>,
pub verify: Option<bool>,
pub no_verify: Option<bool>,
pub push: Option<bool>,
pub disable_push: Option<bool>,
pub push_options: Option<Vec<String>>,
pub dev_version_ext: Option<String>,
pub dev_version: Option<bool>,
pub no_dev_version: Option<bool>,
pub shared_version: Option<bool>,
pub consolidate_commits: Option<bool>,
Expand All @@ -32,6 +37,7 @@ pub struct Config {
pub tag_message: Option<String>,
pub tag_prefix: Option<String>,
pub tag_name: Option<String>,
pub tag: Option<bool>,
pub disable_tag: Option<bool>,
pub enable_features: Option<Vec<String>>,
pub enable_all_features: Option<bool>,
Expand All @@ -55,26 +61,31 @@ impl Config {
if let Some(registry) = source.registry.as_deref() {
self.registry = Some(registry.to_owned());
}
if let Some(disable_release) = source.disable_release {
self.disable_release = Some(disable_release);
if let Some(release) = resolve_bool_arg(source.release, source.disable_release) {
self.release = Some(release);
self.disable_release = None;
}
if let Some(disable_publish) = source.disable_publish {
self.disable_publish = Some(disable_publish);
if let Some(publish) = resolve_bool_arg(source.publish, source.disable_publish) {
self.publish = Some(publish);
self.disable_publish = None;
}
if let Some(no_verify) = source.no_verify {
self.no_verify = Some(no_verify);
if let Some(verify) = resolve_bool_arg(source.verify, source.no_verify) {
self.verify = Some(verify);
self.no_verify = None;
}
if let Some(disable_push) = source.disable_push {
self.disable_push = Some(disable_push);
if let Some(push) = resolve_bool_arg(source.push, source.disable_push) {
self.push = Some(push);
self.disable_push = None;
}
if let Some(push_options) = source.push_options.as_deref() {
self.push_options = Some(push_options.to_owned());
}
if let Some(dev_version_ext) = source.dev_version_ext.as_deref() {
self.dev_version_ext = Some(dev_version_ext.to_owned());
}
if let Some(no_dev_version) = source.no_dev_version {
self.no_dev_version = Some(no_dev_version);
if let Some(dev_version) = resolve_bool_arg(source.dev_version, source.no_dev_version) {
self.dev_version = Some(dev_version);
self.no_dev_version = None;
}
if let Some(shared_version) = source.shared_version {
self.shared_version = Some(shared_version);
Expand Down Expand Up @@ -109,8 +120,9 @@ impl Config {
if let Some(tag_name) = source.tag_name.as_deref() {
self.tag_name = Some(tag_name.to_owned());
}
if let Some(disable_tag) = source.disable_tag {
self.disable_tag = Some(disable_tag);
if let Some(tag) = resolve_bool_arg(source.tag, source.disable_tag) {
self.tag = Some(tag);
self.disable_tag = None;
}
if let Some(enable_features) = source.enable_features.as_deref() {
self.enable_features = Some(enable_features.to_owned());
Expand Down Expand Up @@ -147,19 +159,19 @@ impl Config {
}

pub fn release(&self) -> bool {
!self.disable_release.unwrap_or(false)
resolve_bool_arg(self.release, self.disable_release).unwrap_or(true)
}

pub fn publish(&self) -> bool {
!self.disable_publish.unwrap_or(false)
resolve_bool_arg(self.publish, self.disable_publish).unwrap_or(true)
}

pub fn verify(&self) -> bool {
!self.no_verify.unwrap_or(false)
resolve_bool_arg(self.verify, self.no_verify).unwrap_or(true)
}

pub fn push(&self) -> bool {
!self.disable_push.unwrap_or(false)
resolve_bool_arg(self.publish, self.disable_publish).unwrap_or(true)
}

pub fn push_options(&self) -> &[String] {
Expand All @@ -174,7 +186,7 @@ impl Config {
}

pub fn dev_version(&self) -> bool {
!self.no_dev_version.unwrap_or(false)
resolve_bool_arg(self.dev_version, self.no_dev_version).unwrap_or(true)
}

pub fn shared_version(&self) -> bool {
Expand Down Expand Up @@ -237,7 +249,7 @@ impl Config {
}

pub fn tag(&self) -> bool {
!self.disable_tag.unwrap_or(false)
resolve_bool_arg(self.tag, self.disable_tag).unwrap_or(true)
}

pub fn enable_features(&self) -> &[String] {
Expand Down Expand Up @@ -495,6 +507,18 @@ pub fn resolve_config(workspace_root: &Path, manifest_path: &Path) -> Result<Con
Ok(config)
}

fn resolve_bool_arg(yes: Option<bool>, no: Option<bool>) -> Option<bool> {
match (yes, no) {
(Some(_), Some(_)) => panic!("`disable_` flags are deprecated and can't be set at the same time with their positive versions"),
(Some(yes), None) => Some(yes),
(None, Some(no)) => {
log::warn!("Negative config values are deprecated (`no_`, `disable_`)");
Some(!no)
},
(None, None) => None,
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 9717045

Please sign in to comment.