Skip to content

Commit

Permalink
fix!: Remove --upgrade <policy> support
Browse files Browse the repository at this point in the history
In preparing `cargo-add` for upstreaming into cargo, this feature felt
far enough from being ready that it didn't seem worth putting behind a
feature flag.

The policy names don't map well to what Rust developers are used to
(operator characters) and the policy name for ^ isn't correct, calling
it `minor`.

Removing it seems acceptable because
- Most people use the default policy and we should generally be
  encouraging that because too often people try to out smart the default
  policy and things break.
- Redundant with `--vers <req>` and `<name>@<req>` except when no
  version is specified and cargo-add looks up the latest. If someone does
  want to specify it, they are most likely to specify = which means they
  probably have a reason and a specific version in mind rather than
  "latest".
  • Loading branch information
epage committed Jan 26, 2022
1 parent ad1c6cc commit 8e50285
Show file tree
Hide file tree
Showing 24 changed files with 12 additions and 157 deletions.
46 changes: 7 additions & 39 deletions src/bin/add/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,6 @@ pub struct Args {
)]
pub pkgid: Option<String>,

/// Choose method of semantic version upgrade. Must be one of "none" (exact version, `=`
/// modifier), "patch" (`~` modifier), "minor" (`^` modifier), "all" (`>=`), or "default" (no
/// modifier).
#[clap(
long,
value_name = "METHOD",
possible_value = "none",
possible_value = "patch",
possible_value = "minor",
possible_value = "all",
possible_value = "default",
default_value = "default"
)]
pub upgrade: String,

/// Include prerelease versions when fetching from crates.io (e.g.
/// '0.6.0-alpha').
#[clap(long)]
Expand Down Expand Up @@ -223,11 +208,8 @@ impl Args {
p.manifest_path.parent().map(|p| p.as_std_path())
== Some(dep_path.as_path())
}) {
let v = format!(
"{prefix}{version}",
prefix = self.get_upgrade_prefix(),
version = package.version
);
let op = "";
let v = format!("{op}{version}", op = op, version = package.version);

dependency = dependency.set_version(&v);
}
Expand Down Expand Up @@ -283,11 +265,8 @@ impl Args {
);
// dev-dependencies do not need the version populated
if !self.dev {
let v = format!(
"{prefix}{version}",
prefix = self.get_upgrade_prefix(),
version = package.version
);
let op = "";
let v = format!("{op}{version}", op = op, version = package.version);
dependency = dependency.set_version(&v);
}
} else {
Expand All @@ -297,9 +276,10 @@ impl Args {
&manifest_path,
Some(&registry_url),
)?;
let op = "";
let v = format!(
"{prefix}{version}",
prefix = self.get_upgrade_prefix(),
"{op}{version}",
op = op,
// If version is unavailable `get_latest_dependency` must have
// returned `Err(FetchVersionError::GetVersion)`
version = dependency.version().unwrap_or_else(|| unreachable!())
Expand Down Expand Up @@ -357,17 +337,6 @@ impl Args {
})
.collect()
}

fn get_upgrade_prefix(&self) -> &'static str {
match self.upgrade.as_ref() {
"default" => "",
"none" => "=",
"patch" => "~",
"minor" => "^",
"all" => ">=",
_ => unreachable!(),
}
}
}

#[cfg(test)]
Expand All @@ -388,7 +357,6 @@ impl Default for Args {
optional: false,
manifest_path: None,
pkgid: None,
upgrade: "minor".to_string(),
allow_prerelease: false,
features: None,
no_default_features: false,
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/add/dev_build_conflict.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stderr = """
error: The argument '--dev' cannot be used with '--build'
USAGE:
cargo add --dev --upgrade <METHOD> <CRATE>...
cargo add --dev <CRATE>...
For more information try --help
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/add/git_conflicts_path.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stderr = """
error: The argument '--git <URI>' cannot be used with '--path <PATH>'
USAGE:
cargo add --git <URI> --upgrade <METHOD> <CRATE>...
cargo add --git <URI> <CRATE>...
For more information try --help
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/add/git_conflicts_registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stderr = """
error: The argument '--git <URI>' cannot be used with '--registry <REGISTRY>'
USAGE:
cargo add --git <URI> --upgrade <METHOD> <CRATE>...
cargo add --git <URI> <CRATE>...
For more information try --help
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/cmd/add/git_conflicts_vers.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stderr = """
error: The argument '--git <URI>' cannot be used with '--vers <URI>'
USAGE:
cargo add --git <URI> --upgrade <METHOD> <CRATE>...
cargo add --git <URI> <CRATE>...
For more information try --help
"""
Expand Down
1 change: 0 additions & 1 deletion tests/cmd/add/invalid_op.in

This file was deleted.

3 changes: 0 additions & 3 deletions tests/cmd/add/invalid_op.out/Cargo.toml

This file was deleted.

17 changes: 0 additions & 17 deletions tests/cmd/add/invalid_op.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/cmd/add/invalid_optional_dev.in

This file was deleted.

3 changes: 0 additions & 3 deletions tests/cmd/add/invalid_optional_dev.out/Cargo.toml

This file was deleted.

16 changes: 0 additions & 16 deletions tests/cmd/add/invalid_optional_dev.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/cmd/add/op_caret.in

This file was deleted.

6 changes: 0 additions & 6 deletions tests/cmd/add/op_caret.out/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions tests/cmd/add/op_caret.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/cmd/add/op_equal.in

This file was deleted.

6 changes: 0 additions & 6 deletions tests/cmd/add/op_equal.out/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions tests/cmd/add/op_equal.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/cmd/add/op_greater_eq.in

This file was deleted.

6 changes: 0 additions & 6 deletions tests/cmd/add/op_greater_eq.out/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions tests/cmd/add/op_greater_eq.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/cmd/add/op_tilde.in

This file was deleted.

6 changes: 0 additions & 6 deletions tests/cmd/add/op_tilde.out/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions tests/cmd/add/op_tilde.toml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/cmd/add/registry_conflicts_path.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stderr = """
error: The argument '--registry <REGISTRY>' cannot be used with '--path <PATH>'
USAGE:
cargo add --registry <REGISTRY> --upgrade <METHOD> <CRATE>...
cargo add --registry <REGISTRY> <CRATE>...
For more information try --help
"""
Expand Down

0 comments on commit 8e50285

Please sign in to comment.