34 Commits

Author SHA1 Message Date
Ed Page
eac1ad1cd3 fix(shell): Don't bold the colon after error/warn/note 2025-09-05 09:40:24 -05:00
Ed Page
7d6d673e23 fix(cli): Adjust terminal styles to match rustc
Fixes #12740
2025-09-04 16:35:40 -05:00
Eric Huss
1ce8023626 Rustfmt 2024 2025-07-05 19:50:36 -07:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
NOOMA-42
3ea0e6b751
feat: vcs, color, and message format native completion 2025-03-20 22:16:27 +08:00
Weihang Lo
4240e722d4
test: requires attribute accepts string literals for cmds
The new syntax is key-value pair like `requires = "rustfmt"`,
comparing to the previous `requires_<cmd>`.
2024-11-29 22:23:08 -05:00
Ed Page
81411ec545 feat: Stabilize Edition 2024 2024-11-25 09:27:09 -06:00
Weihang Lo
b4253e5057
fix(help): mention --config <PATH> in help text 2024-10-01 14:54:52 -04:00
Ed Page
a49921f829 fix(test)!: Clarify extension trait role with rename
When browsing the docs, I feel like this will make it easier to tell the
role of these traits within the API.
Or in other words, I can easily tell that these fill a support role and
for what, so I know when I care to look into them.

We use this naming pattern for
`cargo_test_support::paths::CargoPathExt`.
2024-07-18 20:52:22 -05:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
Ed Page
9af864ee55 refactor: Resolve deprecations 2024-05-27 21:27:03 -05:00
Ed Page
4a6f25c112 refactor: Resolve snapbox deprecations 2024-05-27 10:28:13 -05:00
Tobias Bucher
a29742a396 Use u64 rather than usize as "default integer" in library template
`usize` was renamed from `uint` in order to convey that it's not the
"default integer type". Guide new users to use integers with specific
bit width instead of `usize`.
2024-05-22 16:11:00 +02:00
Weihang Lo
26b2e74e55
docs: clarify --locked disallows changes in Cargo.lock 2024-03-28 12:08:57 -04:00
Weihang Lo
e549bc809b
fix(cli): resolve confusion between --frozen and --locked 2024-03-27 22:05:03 -04:00
bors
ecb89a1a4e Auto merge of #13606 - dvdhrm:pr/initlib, r=weihanglo
cargo/init: avoid target.name assignments if possible

Make `cargo init` skip `target.name` assignments if the default value is suitable.

Currently, all paths of `cargo init` will set target-names to the package-name, ensuring that a suitable target-name is set. This is required for all targets but libraries. Unfortunately, library-names have more restrictions than other targets. For example, creating a library with dashes will lead to errors:

    mkdir foo-bar
    cd foo-bar
    touch foo-bar.rs
    cargo init --lib

Fortunately, target-names for libraries are inferred from the package-name. Hence, by omitting the target-name, a valid configuration will be produced.

Instead of adjusting `SourceFileInformation::target_name` to use `Option<String>`, this commit strips the field completely, since all callers set it to the package-name.

Fixes: #11259
2024-03-19 15:39:48 +00:00
David Rheinsberg
b673c1010f cargo/init: avoid target.name assignments if possible
Make `cargo init` skip `target.name` assignments if the default value is
suitable.

Currently, all paths of `cargo init` will set target-names to the
package-name, ensuring that a suitable target-name is set. This is
required for all targets but libraries. Unfortunately, library-names
have more restrictions than other targets. For example, creating a
library with dashes will lead to errors:

    mkdir foo-bar
    cd foo-bar
    touch foo-bar.rs
    cargo init --lib

Fortunately, target-names for libraries are inferred from the
package-name. Hence, by omitting the target-name, a valid configuration
will be produced.

Instead of adjusting `SourceFileInformation::target_name` to use
`Option<String>`, this commit strips the field completely, since all
callers set it to the package-name.

Signed-off-by: David Rheinsberg <david@readahead.eu>
2024-03-19 11:07:41 +01:00
Martin Robinson
8fa25ba41d chore: Fix minor grammar nit in command-line help
A *very* minor grammar correction. "Require" used in this way is
typically followed by the infinitive.
2024-03-18 14:32:28 +01:00
Ed Page
b14a70fe09 test(cli): Verify terminal styling
This uses a new feature from snapbox that let's us render terminal
styling in SVG files.  This let's us see / visualize ANSI escape codes,
including in github's UI (will render images, including side-by-side
images for diffs).
2024-02-21 20:20:41 -06:00
Ed Page
ac453f1c37 test: Remove empty snapshots for UI tests 2024-02-20 13:29:09 -06:00
Ed Page
2e878a4c38 test: Remove empty snapshots for help 2024-02-20 13:05:16 -06:00
Ed Page
9f31f8c675 chore: Update snapbox 2024-02-16 10:27:48 -06:00
Lin Yihai
9be95dfb1c feat: Add hint for adding members to workspace 2024-02-06 13:30:56 +08:00
Ed Page
7513b412fe fix(new): Print a note, rather than a comment, for more information
Fixes #12210
2024-01-29 15:38:04 -06:00
Ed Page
db54c040ae fix(new): Print a 'Creating', rather than 'Created' status
This has bothered me about `cargo new` and `cargo init` for a while that
the output is read backwards, for example:
```diff
--- i/tests/testsuite/cargo_init/path_contains_separator/stderr.log
+++ w/tests/testsuite/cargo_init/path_contains_separator/stderr.log
@@ -1,3 +1,3 @@
+    Creating binary (application) package
 warning: the path `[ROOT]/case/test:ing/.` contains invalid PATH characters (usually `:`, `;`, or `"`)
 It is recommended to use a different name to avoid problems.
-     Created binary (application) package
```
2024-01-29 15:29:10 -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
David Calavera
1a8bfdf0cf Update workspace manifest with new members.
When a user runs `cargo new` or `cargo init` within a workspace, Cargo will automatically add the new package to the members list in the workspace if necessary. The heuristic to add the new package is as follows:

- If there is no `members` list in the workspace yet, a new `members` list is created.
- If there is an `exclude` statement, Cargo checks if the new package should be excluded. If it doesn't match the `exclude` list, the package is added to the `members` list.
- If there is a glob expression in the `members` list that matches the new package, the package is not added to the `members` list.
- If the existent `members` list is sorted, Cargo tries to preserve the ordering when it adds the new package.

This change doesn't try to format the resulting `members` list in any way, leaving the formatting decissions to the user.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-28 07:42:23 -07:00
Ed Page
99f917a67e fix(help): Consistently use SCREAMING_CASE for value names
- We have some positional value names that are SCREAMING_CASE and some
  that aren't
- All of the value names for our flags are already SCREAMING_CASE
2023-10-17 16:47:44 -05:00
Scott Schafer
b2b3cfa524
feat: Add Edition2024 2023-10-04 13:11:52 -06:00
Ed Page
ad0a11349e fix(help): Remove redundant information from new/init
Auditing all of the `--help` in prep for #12578 and noticed that we list
the VCS information twice, once on our end and once by clap.
2023-08-29 16:28:49 -05:00
Charles Samborski
54ad4a01df fix(new): Don't ignore Cargo.lock for all package types
Following the default guidance to commit a lockfile, this updates
`cargo new` to do it by default.
2023-07-19 11:56:40 -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
Ed Page
79469f3019 refactor(tests): Name init ui tests more consistently
Currently, the UI tests are
- `cargo add`
- `cargo new`
- `cargo remove`
- `init`

One of these is not like the others. This change renames `init` to
`cargo_init` to suggest it is the UI tests for the `cargo init` command,
rather than `init` functionality.
2023-07-24 13:39:37 -05:00