Skip to content
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

Add a way to configure the format of the version string #436

Closed
wants to merge 1 commit into from
Closed

Add a way to configure the format of the version string #436

wants to merge 1 commit into from

Conversation

pwoolcoc
Copy link
Contributor

@pwoolcoc pwoolcoc commented Dec 2, 2020

This adds the ability to add a section to a .cargo/config file that
will tell cargo-edit how to format the version string when adding or
upgrading dependencies. By adding a [cargo-edit] section to a
project's or user's .cargo/config, the user can control how versions
are added to a Cargo.toml.

This will only work with exact versions, version ranges are not
supported.

Here is an example that will cause cargo-edit to only print the major
and minor version number for a dependency:

# .cargo/config
[cargo-edit]
version_fmt = "{MAJOR}.{MINOR}"

You can also have separate formats for adding vs upgrading:

# .cargo/config
[cargo-edit.add]
version_fmt = "{MAJOR}.{MINOR}.{PATCH}"

[cargo-edit.upgrade]
version_fmt = "{MAJOR}"

Closes #126

This adds the ability to add a section to a `.cargo/config` file that
will tell cargo-edit how to format the version string when adding or
upgrading dependencies. By adding a `[cargo-edit]` section to a
project's or user's `.cargo/config`, the user can control how versions
are added to a Cargo.toml.

This will only work with exact versions, version ranges are not
supported.

Here is an example that will cause cargo-edit to only print the major
and minor version number for a dependency:

```toml
[cargo-edit]
version_fmt = "{MAJOR}.{MINOR}"
```

You can also have separate formats for adding vs upgrading:

```toml
[cargo-edit.add]
version_fmt = "{MAJOR}.{MINOR}.{PATCH}"

[cargo-edit.upgrade]
version_fmt = "{MAJOR}"
```

Closes #126
@shikhar
Copy link

shikhar commented Jan 12, 2022

We would like to have predictable lock-files with Bazel rules_rust (which can inter-operate with Cargo so still use this plugin for upgrading dependencies). This requires specifying exact versions ={MAJOR}.{MINOR}.{PATCH}, so this kind of templating capability would be a very useful feature for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo add: include only MAJOR.MINOR
2 participants