killercup / cargo-edit

A utility for managing cargo dependencies from the command line.
http://killercup.github.io/cargo-edit/
MIT License
3.07k stars 148 forks source link

Merge cargo-add into cargo #568

Closed epage closed 2 years ago

epage commented 2 years ago

This is more a scratchpad for myself to iterate on thoughts without pinging everybody in https://github.com/rust-lang/cargo/pull/8062#issuecomment-606910003

epage commented 2 years ago

Draft of the proposal to merge

This is a proposal to merge cargo-add into cargo

Motivation

In addition to users being used to this as they migrate from other ecosystems (see prior art), this provides guard rails to help the user avoid errors and even guide them to best practices, including

Drawbacks

This is another area of consideration for new RFCs like rust-lang/rfcs#3143 or rust-lang/rfcs#2906

This is a high UX feature that will draw a lot of attention (ie Issue influx), e.g.

Behavior

Help output

```console $ cargo-add 0.8.0 cargo-add 0.8.0 Add dependency to a Cargo.toml manifest file USAGE: cargo add [OPTIONS] ... ARGS: ... Crates to be added OPTIONS: --allow-prerelease Include prerelease versions when fetching from crates.io (e.g. '0.6.0-alpha') -B, --build Add crate as build dependency --branch Specify a git branch to download the crate from -D, --dev Add crate as development dependency --features Space-separated list of features to add. For an alternative approach to enabling features, consider installing the `cargo-feature` utility --git Specify a git repository to download the crate from -h, --help Print help information --manifest-path Path to the manifest to add a dependency to --no-default-features Set `default-features = false` for the added dependency --offline Run without accessing the network --optional Add as an optional dependency (for use in features) -p, --package Package id of the crate to add this dependency to --path Specify the path the crate should be loaded from --quiet Do not print any output in case of success -r, --rename Rename a dependency in Cargo.toml, https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml. Only works when specifying a single dependency --registry Registry to use --rev Specify a git branch to download the crate from -s, --sort Sort dependencies even if currently unsorted --tag Specify a git branch to download the crate from --target Add as dependency to the given target platform --upgrade Choose method of semantic version upgrade. Must be one of "none" (exact version, `=` modifier), "patch" (`~` modifier), "minor" (`^` modifier), "all" (`>=`), or "default" (no modifier) [default: default] [possible values: none, patch, minor, all, default] -V, --version Print version information --vers Specify the version to grab from the registry(crates.io). You can also specify version as part of name, e.g `cargo add bitflags@0.3.2` This command allows you to add a dependency to a Cargo.toml manifest file. If is a github or gitlab repository URL, or a local path, `cargo add` will try to automatically get the crate name and set the appropriate `--git` or `--path` value. Please note that Cargo treats versions like '1.2.3' as '^1.2.3' (and that '^1.2.3' is specified as '>=1.2.3 and <2.0.0'). By default, `cargo add` will use this format, as it is the one that the crates.io registry suggests. One goal of `cargo add` is to prevent you from using wildcard dependencies (version set to '*'). ```

Example commands

cargo add regex
cargo add regex serde
cargo add regex@1
cargo add regex@~1.0
cargo add regex --vers 1.0
cargo add regex --upgrade minor  # for some reason this is the policy name for `^`
cargo add https://github.com/rust-lang/regex
cargo add regex --git https://github.com/rust-lang/regex
cargo add ../dependency
cargo add dep --path ../dependency

For an exhaustive set of examples, see test .toml specs

Particular points

Alternatives

Prior Art

Future Possibilities

For more, see https://github.com/killercup/cargo-edit/issues?q=is%3Aissue+is%3Aopen+label%3Acargo-add

Questions