-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: MVP for cargo set-version
#482
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ Currently available subcommands: | |
- [`cargo add`](#cargo-add) | ||
- [`cargo rm`](#cargo-rm) | ||
- [`cargo upgrade`](#cargo-upgrade) | ||
- [`cargo set-version`](#cargo-set-version) | ||
|
||
[](https://github.com/killercup/cargo-edit/actions) | ||
[](https://travis-ci.org/killercup/cargo-edit) | ||
|
@@ -227,7 +228,7 @@ upgrade to for each can be specified with e.g. `[email protected]` or `serde@>=0.9,<2 | |
Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are | ||
supported. Git/path dependencies will be ignored. | ||
All packages in the workspace will be upgraded if the `--workspace` flag is supplied. | ||
All packages in the workspace will be upgraded if the `--workspace` flag is supplied. | ||
The `--workspace` flag may be supplied in the presence of a virtual manifest. | ||
If the '--to-lockfile' flag is supplied, all dependencies will be upgraded to the currently locked | ||
|
@@ -236,6 +237,54 @@ up-to-date. If the lock file is missing, or it needs to be updated, cargo-upgrad | |
error. If the '--to-lockfile' flag is supplied then the network won't be accessed. | ||
``` | ||
|
||
### `cargo set-version` | ||
|
||
Set the version in your `Cargo.toml`. | ||
|
||
#### Examples | ||
|
||
```sh | ||
# Set the version to the version 1.0.0 | ||
$ cargo set-version 1.0.0 | ||
# Bump the version to the next major | ||
$ cargo set-version --bump major | ||
# Bump version to the next minor | ||
$ cargo set-version --bump minor | ||
# Bump version to the next patch | ||
$ cargo set-version --bump patch | ||
``` | ||
|
||
#### Usage | ||
|
||
```plain | ||
cargo-set-version 0.7.0 | ||
Change a package's version in the local manifest file (i.e. Cargo.toml) | ||
USAGE: | ||
cargo set-version [FLAGS] [OPTIONS] [--] [target] | ||
FLAGS: | ||
--all [deprecated in favor of `--workspace`] | ||
--dry-run Print changes to be made without making them | ||
-h, --help Prints help information | ||
-V, --version Prints version information | ||
--workspace Modify all packages in the workspace | ||
OPTIONS: | ||
--bump <bump> Increment manifest version [possible values: major, minor, patch, | ||
release, rc, beta, alpha] | ||
--exclude <exclude>... Crates to exclude and not modify | ||
--manifest-path <path> Path to the manifest to upgrade | ||
-m, --metadata <metadata> Specify the version metadata field (e.g. a wrapped libraries version) | ||
-p, --package <pkgid> Package id of the crate to change the version of | ||
ARGS: | ||
<target> Version to change manifests to | ||
``` | ||
|
||
For more on `metadata`, see the | ||
[semver crate's documentation](https://docs.rs/semver/1.0.4/semver/struct.BuildMetadata.html). | ||
|
||
## License | ||
|
||
Apache-2.0/MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::path::PathBuf; | ||
|
||
use structopt::{clap::AppSettings, StructOpt}; | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(bin_name = "cargo")] | ||
pub(crate) enum Command { | ||
/// Change a package's version in the local manifest file (i.e. Cargo.toml). | ||
#[structopt(name = "set-version")] | ||
Version(Args), | ||
} | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
#[structopt(group = structopt::clap::ArgGroup::with_name("version").multiple(false))] | ||
pub(crate) struct Args { | ||
/// Version to change manifests to | ||
#[structopt(parse(try_from_str), group = "version")] | ||
pub(crate) target: Option<semver::Version>, | ||
|
||
/// Increment manifest version | ||
#[structopt(long, possible_values(&crate::version::BumpLevel::variants()), group = "version")] | ||
pub(crate) bump: Option<crate::version::BumpLevel>, | ||
|
||
/// Specify the version metadata field (e.g. a wrapped libraries version) | ||
#[structopt(short = "m", long)] | ||
pub metadata: Option<String>, | ||
|
||
/// Path to the manifest to upgrade | ||
#[structopt(long = "manifest-path", value_name = "path", conflicts_with = "pkgid")] | ||
pub(crate) manifest_path: Option<PathBuf>, | ||
|
||
/// Package id of the crate to change the version of. | ||
#[structopt( | ||
long = "package", | ||
short = "p", | ||
value_name = "pkgid", | ||
conflicts_with = "path", | ||
conflicts_with = "all", | ||
conflicts_with = "workspace" | ||
)] | ||
pub(crate) pkgid: Option<String>, | ||
|
||
/// Modify all packages in the workspace. | ||
#[structopt( | ||
long = "all", | ||
help = "[deprecated in favor of `--workspace`]", | ||
conflicts_with = "workspace", | ||
conflicts_with = "pkgid" | ||
)] | ||
pub(crate) all: bool, | ||
|
||
/// Modify all packages in the workspace. | ||
#[structopt(long = "workspace", conflicts_with = "all", conflicts_with = "pkgid")] | ||
pub(crate) workspace: bool, | ||
|
||
/// Print changes to be made without making them. | ||
#[structopt(long = "dry-run")] | ||
pub(crate) dry_run: bool, | ||
|
||
/// Crates to exclude and not modify. | ||
#[structopt(long)] | ||
pub(crate) exclude: Vec<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error_chain! { | ||
errors { | ||
/// We do not support this version requirement at this time | ||
UnsupportedVersionReq(req: String) { | ||
display("Support for modifying {} is currently unsupported", req) | ||
} | ||
/// User requested to downgrade a crate | ||
VersionDowngreade(current: semver::Version, requested: semver::Version) { | ||
display("Cannot downgrade from {} to {}", current, requested) | ||
} | ||
} | ||
links { | ||
CargoEditLib(::cargo_edit::Error, ::cargo_edit::ErrorKind); | ||
} | ||
foreign_links { | ||
CargoMetadata(::failure::Compat<::cargo_metadata::Error>); | ||
Version(::semver::Error)#[doc = "An error from the semver crate"]; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did bring up that the current name is what drove me to not overload the version field with relative bumps but to push that out to
--bump
. The side benefit is error reporting is more complicated when mixing fields.Personally, I have no real preference within the scope of
cargo-edit
. I do wonder what would be the more appropriate name if we upstream this intocargo
. I would suspect a more explicit name (ie hasversion
in it).I thought I'd look around for other tools
version