Commit graph

56 commits

Author SHA1 Message Date
Lin Yihai
509535675b Make the public/no-public next to the pair optional/no-optional 2023-11-27 08:09:54 +08:00
Lin Yihai
58e0ab825b reuse add_basic.in/lib.rs for testcase 2023-11-25 12:41:01 +08:00
Lin Yihai
9ac30323b3 Add not overwrite testcase for cargo add --public 2023-11-25 11:29:39 +08:00
Lin Yihai
7c8d997e26 Add overwrite testcase for cargo add --public 2023-11-24 15:11:51 +08:00
Lin Yihai
a1a75e81c9 Update cargo add --help testcase 2023-11-24 15:04:52 +08:00
Ed Page
0d29d3f71b fix(resolver): Prefer MSRV, rather than ignore incompatible
This is another experiment for #9930.

Comparing preferring over exclusively using MSRV compatible:

Benefits
- Better error messages
- `--ignore-rust-version` is implicitly sticky

Downsides
- Can't backtrack for MSRV compatible version
- Still requires workspace-wide MSRV (compared to our desired end state of declaring MSRV as yet another dependency)

This builds on #12930
2023-11-14 14:56:58 -06:00
Eric Huss
80ffb1de1c Fix --quiet being used with nested subcommands.
This fixes an issue where `--quiet` doesn't work with commands that have
subcommands. This is because `config_configure` only looks at the global
and top-level subcommand, and not deeper subcommands. The issue was that
`--quiet` was not defined as a global flag. This was changed in
https://github.com/rust-lang/cargo/pull/6358 in order to give a better
help message for `cargo test --quiet`. I don't remember if clap just
didn't support overriding at the time, or if we just didn't know how it
worked. Anyways, it seems to work to override it now, so I think it
should be fine to mark it as global.

This should bring in `--quiet` more in-line with how `--verbose` works.
This means that `--quiet` is now accepted with `cargo report`,
`cargo help`, and `cargo config`.

This also fixes `--quiet` with `cargo clean gc`.

This should also help with supporting `--quiet` with the new `cargo
owner` subcommands being added in
https://github.com/rust-lang/cargo/pull/11879.

Fixes #12957
2023-11-12 11:17:43 -08:00
Ed Page
02dd917511 fix(add): Add back in some auto-formatting
This moves the auto-format to the correct place so it takes effect.
2023-10-17 12:48:45 -05:00
Ed Page
99e4847d78 fix(add): Stop auto-formatting content
Huh, overlooked the cargo side when I fixed this in killercup/cargo-edit#725

Fixes #10850
2023-10-17 12:48:08 -05:00
Ed Page
716ae6238f test(add): Check table formatting issues 2023-10-17 12:23:45 -05:00
Angelo Ross
72dccecb19
Display only feature list or summarized on cargo add 2023-09-19 13:14:44 -03:00
bors
695416e8d8 Auto merge of #12660 - epage:dry, r=weihanglo
feat(cli): Add '-n' to dry-run

This came from #12638 and my many small frustrations from wanting to use `-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-18 02:53:19 +00:00
Angelo Ross
9928689d2c
Limit features printed during cargo add 2023-09-14 08:36:44 -03:00
Angelo Ross
3a40df85d6
Showcase output with too many features 2023-09-13 11:58:48 -03:00
Ed Page
033e06a1cc feat(cli): Add '-n' to dry-run
This came from #12638 and my many small frustrations from wanting to use
`-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would
not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see
https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-12 13:42:00 -05:00
Ed Page
4820624ce7 feat(resolver): Respect MSRV 2023-08-25 10:42:26 -05:00
Ed Page
5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Ed Page
853102f7de fix(cli): Make --help easier to browse
This mirrors some of the categories from `cargo help` (the man pages).
There are fewer categories to avoid extra vertical space.  Instead, they
are left int the `Options` category but put first.
2023-08-08 13:50:05 -05:00
Ed Page
5101372312 test(cli): Track --help output
This makes it easier to evaluate the usability of PRs, like #11905
2023-07-24 17:12:20 -05:00
Danil Hendra Suryawan
a9c47cc3ab feat(cli): emit error when add is given a toolchain name instead of a crate name 2023-06-03 20:50:24 +07:00
bors
8f49b5556b Auto merge of #12191 - epage:mut, r=weihanglo
fix(add): Reduce the chance we re-format the user's `[features]` table

### What does this PR try to resolve?

#11743 pointed out that we re-format the users `[features]` table when running `cargo add`  which was a bug introduced in #11099.

This reduces the chance people will run into this problem
- Reducing the scope of the `fmt` call
- Preserving formatting in a simple case

Actually removing the `fmt` case can make some common formatting cases more complex to do "right", so I'm punting on that for now.

### How should we test and review this PR?

Look at the individual commits as I show how each change improves the behavior of `cargo add`.
2023-05-27 10:33:39 +00:00
Ed Page
0da6997ccc test(add): Remove expensive test
This is a carry-over from cargo-edit where we had to worry about the UX
of all of the behavior while now we are just relying on built-in cargo
behavior and don't need to test it specifically for `cargo add`.

On my machine, this test takes 11s.
2023-05-26 19:24:13 -05:00
Ed Page
dbf9134d57 fix(add): Preserve formatting 2023-05-26 16:49:59 -05:00
Ed Page
6d8f35f729 fix(add): Reduce the chance of breaking the user's formatting 2023-05-26 16:49:59 -05:00
Ed Page
b903527f28 test(add): Show features table fmt bug 2023-05-26 16:49:14 -05:00
Ed Page
29dc47fa9a refactor(tests): Reduce cargo-add setup load
This just gets rid of irrelevant packages in the registry.  Looking into
which versions aren't needed would require a deeper pass, so I held off
on that for now.

Before, the tests were in the 300-500ms range and now they take
100-300ms.

This did call to my attention that `unrelated` is misspelled as
`unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 09:24:45 -05:00
cassaundra
30a445b9a4
Add tests for cargo add's rust-version behavior 2023-05-23 11:06:08 -07:00
hi-rustin
e0276cae19 Update error message to not start with capital letters
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 09:16:45 +08:00
hi-rustin
4d401bd0b9 Add test for empty dep table error
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-04-20 08:49:30 +08:00
Ed Page
6feea34f8a chore: Upgrade to clap v4.2
Tests in `master` are currently failing because its building with clap
v4.2 but the tests have snapshots from v4.1
2023-03-28 05:00:49 -05:00
jofas
feef14e9d7 breaking endless loop on cyclic features in cargo-add 2023-03-06 13:04:38 +01:00
Scott Schafer
08c6bb8446 refactor: Rename test names to case for cargo_add 2023-02-20 11:25:14 -06:00
Ed Page
6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
bors
04519ad831 Auto merge of #11612 - hi-rustin:rustin-patch-cargo-add, r=epage
`cargo add` check `[dependencies]` order without considering the dotted item

### What does this PR try to resolve?

Try to close https://github.com/rust-lang/cargo/issues/11584

`cargo check` check `[dependencies]` order without considering the dotted item.

### How should we test and review this PR?
See the unit test.
2023-01-25 15:44:23 +00:00
Ed Page
8fb9effcae test: Update for clap 4.1.3
The latest clap release fixed a bug with the algorithm for providing
suggestions, leading this suggestion to change.
2023-01-23 21:19:48 -06:00
hi-rustin
ea5ade3426 cargo check check [dependencies] order without considering the dotted item
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-01-22 22:55:07 +08:00
Weihang Lo
c51c6bb6ac
chore: reflect to clap updates 2023-01-14 09:23:39 +00:00
Philpax
249683b456
fix(tests): update to match add change 2022-12-15 09:34:23 +01:00
hi-rustin
6b24d5c761 Rename infer_package to infer_package_for_git_source
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-10-10 22:19:32 +08:00
hi-rustin
6ae292100b Update cargo add test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-10-07 19:00:14 +08:00
Ed Page
96948f7a24 refactor(cli): Upgrade to clap v4 2022-09-28 13:32:14 -05:00
Emil Gardström
1cc21b65d1
make unknown features on cargo add more discoverable 2022-09-21 08:07:16 +02:00
Ed Page
be257b8b25 fix(add): Remove redundant version in build metadata cases 2022-09-12 09:51:38 -05:00
Ed Page
7ce2b7d42a fix(add): Limit 'Features as of vX.Y.Z' to when relevant
This will only show the messaeg if we didn't already show a version req
with full precision specified ... mostly.  We'll also skip it if its a
local or git dependency but we never show the version in those cases
because it doesn't matter.

The `precise_version` logic came from cargo-upgrade.
2022-09-12 09:46:22 -05:00
Ed Page
73906aeaf8 fix(add): Clarify which version the features are added for
This gives a hint to users that we might not be showing the feature list
for the latest version but the earliest version.

Also when using a workspace dependency or re-using an existing
dependency, this is a good reminder of what the version requirement is
that was selected.

However, when the user or add (the common case) selected a full
precision requirement, this is redundant.

I'm also mixed on whether the meta version should show up.

Fixes #11073
2022-09-12 09:39:47 -05:00
Ed Page
5789c12e45 fix(add): Update the lock file
This is done in the command, rather than in the op,
- To consistently construct the `Workspace`
- It is more composable as an API

A downside is we update the git dependencies a second time.

We are not rolling back on error.
- For some errors, the user might want to debug what went wrong
- Rollback adds its own complications and risks, including since its
  non-atomic

Fixes #10901
2022-07-26 14:59:07 -05:00
Ed Page
323c7bc306 test(add): Make test data valid
Resolving the manifests will fail due to inconsistencies.  This
addresses those.
2022-07-25 11:06:12 -05:00
Ed Page
b5c4a765ef fix(add): Respect --locked
This is prep for #10901 to avoid the most common failure case for the
lock file.  We are assuming if the users action caused a change in the
manifes, then it will cause a change in the lock file.  This isn't
entirely true but close enough and I think these semantics can make
sense.
2022-07-25 09:52:00 -05:00
Scott Schafer
2c810afda9 Stabilize workspace inheritance 2022-07-23 09:36:49 -05:00
Scott Schafer
c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00