Commit graph

71 commits

Author SHA1 Message Date
bors
269783715b Auto merge of #13272 - linyihai:cargo-add-public-manpage, r=epage
doc: add `public` info in `cargo-add` man page.

### What does this PR try to resolve?
follow up https://github.com/rust-lang/cargo/pull/13046
add `public/private` explanation for `cargo-add` in man page.

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

### Additional information

The help info would be like this

- `cargo help add`
```
        --public
           Mark the dependency as public.

           The dependency can be referenced in your library’s public API.

           Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>

       --no-public
           Mark the dependency as private.

           While you can use the crate in your implementation, it cannot be referenced in your public API.

           Unstable (nightly-only) <https://doc.rust-lang.org/cargo/reference/unstable.html#public-dependency>
```
- `cargo add -h`
```
      --public               Mark the dependency as public (unstable)
      --no-public            Mark the dependency as private (unstable)
```

- `cargo add --help`
```
      --public
          Mark the dependency as public (unstable)

          The dependency can be referenced in your library's public API.

      --no-public
          Mark the dependency as private (unstable)

          While you can use the crate in your implementation, it cannot be referenced in your public API.
```
2024-01-11 21:13:02 +00:00
Lin Yihai
f141c10bda doc: add public info in cargo-add man page. 2024-01-11 15:11:08 +08:00
sanchit
e46d80e24e Fixes #13121: Use Exact query during populating features. Update test
fix target output
2023-12-29 10:03:54 +05:30
sanchit
61f6248a07 add test expecting failure: adding features from git repo w multiple packages 2023-12-29 04:54:50 +05:30
Scott Schafer
0d62ae2fc3
feat: Add rustc style errors for manifest parsing 2023-12-15 13:30:10 -07:00
Ed Page
1da305301c refactor: Validate via RegistryName/PackageName 2023-12-13 13:03:27 -06:00
Ed Page
9de03cd1fd fix(add): Catch empty dep name early 2023-12-13 10:43:55 -06:00
Ed Page
7200646a97 test: Demonstrate existing empty name errors 2023-12-13 10:38:34 -06:00
Lin Yihai
b7b036f3a1 Chore(test): remove unnecesary packages and versions for optionals tests 2023-12-04 11:25:38 +08:00
bors
78109c0d2c Auto merge of #13071 - LuuuXXX:issue-11010, r=epage
Have cargo add --optional <dep> create a <dep> = "dep:<dep> feature

### What does this PR try to resolve?

`cargo add --optional <dep>` would create a `<dep> = "dep:<dep>` feature iff

- `rust-version` is unset or is new enough for the syntax
- `dep:<dep>` doesn't already exist

Fixes https://github.com/rust-lang/cargo/issues/11010

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

As the `dep:` syntax is only available starting with Rust 1.60. this pr maintains the previous usage convention in the earlier version.

run

```shell
cargo add --optional <dep>
```

with different rust-version to verify.
2023-12-01 18:13:54 +00:00
LuuuX
036a03709b Fix issue-11010 2023-12-02 01:36:16 +08:00
Lin Yihai
48c998fec7 Add detect_workspace_inherit_public test case. 2023-12-01 11:22:26 +08:00
Lin Yihai
a6ca281948 chore: add lib.rs for new test cases 2023-12-01 10:21:33 +08:00
Lin Yihai
703446165b chore: add the missing flag for cargo add --public 2023-11-28 11:25:10 +08:00
Lin Yihai
07ba57dd8b Remove unnecessary code for cargo add --public testcases 2023-11-27 08:54:05 +08:00
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