diff --git a/src/bin/cargo/commands/publish.rs b/src/bin/cargo/commands/publish.rs
index 572312eefae..8819c38e4d9 100644
--- a/src/bin/cargo/commands/publish.rs
+++ b/src/bin/cargo/commands/publish.rs
@@ -1,6 +1,7 @@
use crate::command_prelude::*;
use cargo::ops::{self, PublishOpts};
+use cargo_credential::Secret;
pub fn cli() -> Command {
subcommand("publish")
@@ -8,7 +9,11 @@ pub fn cli() -> Command {
.arg_dry_run("Perform all checks without uploading")
.arg_index("Registry index URL to upload the package to")
.arg_registry("Registry to upload the package to")
- .arg(opt("token", "Token to use when uploading").value_name("TOKEN"))
+ .arg(
+ opt("token", "Token to use when uploading")
+ .value_name("TOKEN")
+ .hide(true),
+ )
.arg(flag(
"no-verify",
"Don't verify the contents by building them",
@@ -45,13 +50,16 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
.into());
}
+ let token = args.get_one::("token").cloned().map(Secret::from);
+ if token.is_some() {
+ let _ = gctx.shell().warn("`cargo publish --token` is deprecated in favor of using `cargo login` and environment variables");
+ }
+
ops::publish(
&ws,
&PublishOpts {
gctx,
- token: args
- .get_one::("token")
- .map(|s| s.to_string().into()),
+ token,
reg_or_index,
verify: !args.flag("no-verify"),
allow_dirty: args.flag("allow-dirty"),
diff --git a/src/doc/man/cargo-publish.md b/src/doc/man/cargo-publish.md
index 88ff22f3847..c9f753b671c 100644
--- a/src/doc/man/cargo-publish.md
+++ b/src/doc/man/cargo-publish.md
@@ -28,8 +28,9 @@ following steps:
and may timeout. In that case, you will need to check for completion
manually. This timeout does not affect the upload.
-This command requires you to be authenticated with either the `--token` option
-or using {{man "cargo-login" 1}}.
+This command requires you to be authenticated using {{man "cargo-login" 1}}
+or environment variables of the [`registry.token`](../reference/config.html#registrytoken)
+and [`registries..token`](../reference/config.html#registriesnametoken) config fields.
See [the reference](../reference/publishing.html) for more details about
packaging and publishing.
@@ -44,8 +45,6 @@ packaging and publishing.
Perform all checks without uploading.
{{/option}}
-{{> options-token }}
-
{{#option "`--no-verify`" }}
Don't verify the contents by building them.
{{/option}}
diff --git a/src/doc/man/generated_txt/cargo-publish.txt b/src/doc/man/generated_txt/cargo-publish.txt
index d5170f0ccaf..3ea494a90cb 100644
--- a/src/doc/man/generated_txt/cargo-publish.txt
+++ b/src/doc/man/generated_txt/cargo-publish.txt
@@ -25,8 +25,12 @@ DESCRIPTION
and may timeout. In that case, you will need to check for completion
manually. This timeout does not affect the upload.
- This command requires you to be authenticated with either the --token
- option or using cargo-login(1).
+ This command requires you to be authenticated using cargo-login(1) or
+ environment variables of the registry.token
+
+ and registries..token
+
+ config fields.
See the reference
for more
@@ -37,18 +41,6 @@ OPTIONS
--dry-run
Perform all checks without uploading.
- --token token
- API token to use when authenticating. This overrides the token
- stored in the credentials file (which is created by cargo-login(1)).
-
- Cargo config
- environment variables can be used to override the tokens stored in
- the credentials file. The token for crates.io may be specified with
- the CARGO_REGISTRY_TOKEN environment variable. Tokens for other
- registries may be specified with environment variables of the form
- CARGO_REGISTRIES_NAME_TOKEN where NAME is the name of the registry
- in all capital letters.
-
--no-verify
Don’t verify the contents by building them.
diff --git a/src/doc/src/commands/cargo-publish.md b/src/doc/src/commands/cargo-publish.md
index ccdb093cc05..b8bb1a99303 100644
--- a/src/doc/src/commands/cargo-publish.md
+++ b/src/doc/src/commands/cargo-publish.md
@@ -24,8 +24,9 @@ following steps:
and may timeout. In that case, you will need to check for completion
manually. This timeout does not affect the upload.
-This command requires you to be authenticated with either the `--token` option
-or using [cargo-login(1)](cargo-login.html).
+This command requires you to be authenticated using [cargo-login(1)](cargo-login.html)
+or environment variables of the [`registry.token`](../reference/config.html#registrytoken)
+and [`registries..token`](../reference/config.html#registriesnametoken) config fields.
See [the reference](../reference/publishing.html) for more details about
packaging and publishing.
@@ -40,17 +41,6 @@ packaging and publishing.
Perform all checks without uploading.
---token token
-API token to use when authenticating. This overrides the token stored in
-the credentials file (which is created by cargo-login(1)).
-Cargo config environment variables can be
-used to override the tokens stored in the credentials file. The token for
-crates.io may be specified with the CARGO_REGISTRY_TOKEN environment
-variable. Tokens for other registries may be specified with environment
-variables of the form CARGO_REGISTRIES_NAME_TOKEN where NAME is the name
-of the registry in all capital letters.
-
-
--no-verify
Don’t verify the contents by building them.
diff --git a/src/etc/_cargo b/src/etc/_cargo
index 1ea295594c1..9cd64acba34 100644
--- a/src/etc/_cargo
+++ b/src/etc/_cargo
@@ -251,7 +251,6 @@ _cargo() {
'--index=[specify registry index]:index' \
'--allow-dirty[allow dirty working directories to be packaged]' \
"--no-verify[don't verify the contents by building them]" \
- '--token=[specify token to use when uploading]:token' \
'--dry-run[perform all checks without uploading]'
;;
diff --git a/src/etc/cargo.bashcomp.sh b/src/etc/cargo.bashcomp.sh
index 33e64a9f788..a6aee552c01 100644
--- a/src/etc/cargo.bashcomp.sh
+++ b/src/etc/cargo.bashcomp.sh
@@ -73,7 +73,7 @@ _cargo()
local opt__owner="$opt_common $opt_lock -a --add -r --remove -l --list --index --token --registry"
local opt__package="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty -l --list --no-verify --no-metadata --index --registry --target --target-dir"
local opt__pkgid="$opt_common $opt_mani $opt_lock $opt_pkg"
- local opt__publish="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty --dry-run --token --no-verify --index --registry --target --target-dir"
+ local opt__publish="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty --dry-run --no-verify --index --registry --target --target-dir"
local opt__remove="$opt_common $opt_pkg $opt_lock $opt_mani --dry-run --dev --build --target"
local opt__rm="$opt__remove"
local opt__report="$opt_help $opt_verbose $opt_color future-incompat future-incompatibilities"
diff --git a/src/etc/man/cargo-publish.1 b/src/etc/man/cargo-publish.1
index ba7f2bf68c4..8f0e2eb4a4f 100644
--- a/src/etc/man/cargo-publish.1
+++ b/src/etc/man/cargo-publish.1
@@ -37,8 +37,9 @@ and may timeout. In that case, you will need to check for completion
manually. This timeout does not affect the upload.
.RE
.sp
-This command requires you to be authenticated with either the \fB\-\-token\fR option
-or using \fBcargo\-login\fR(1).
+This command requires you to be authenticated using \fBcargo\-login\fR(1)
+or environment variables of the \fI\f(BIregistry.token\fI\fR
+and \fI\f(BIregistries..token\fI\fR config fields.
.sp
See \fIthe reference\fR for more details about
packaging and publishing.
@@ -50,19 +51,6 @@ packaging and publishing.
Perform all checks without uploading.
.RE
.sp
-\fB\-\-token\fR \fItoken\fR
-.RS 4
-API token to use when authenticating. This overrides the token stored in
-the credentials file (which is created by \fBcargo\-login\fR(1)).
-.sp
-\fICargo config\fR environment variables can be
-used to override the tokens stored in the credentials file. The token for
-crates.io may be specified with the \fBCARGO_REGISTRY_TOKEN\fR environment
-variable. Tokens for other registries may be specified with environment
-variables of the form \fBCARGO_REGISTRIES_NAME_TOKEN\fR where \fBNAME\fR is the name
-of the registry in all capital letters.
-.RE
-.sp
\fB\-\-no\-verify\fR
.RS 4
Don\[cq]t verify the contents by building them.
diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs
index ab0ded2443a..dd8f0d03f05 100644
--- a/tests/testsuite/alt_registry.rs
+++ b/tests/testsuite/alt_registry.rs
@@ -306,6 +306,7 @@ Caused by:
.arg(crates_io.index_url().as_str())
.with_status(101)
.with_stderr_data(str![[r#"
+[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
[UPDATING] crates.io index
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
diff --git a/tests/testsuite/cargo_publish/help/stdout.term.svg b/tests/testsuite/cargo_publish/help/stdout.term.svg
index a455d6cc347..1bf03830cab 100644
--- a/tests/testsuite/cargo_publish/help/stdout.term.svg
+++ b/tests/testsuite/cargo_publish/help/stdout.term.svg
@@ -6,14 +6,14 @@
.fg-bright-green { fill: #55FF55 }
.fg-cyan { fill: #00AAAA }
.container {
- padding: 0 10px;
- line-height: 18px;
+ padding: 0 10px;
+ line-height: 18px;
}
.bold { font-weight: bold; }
tspan {
- font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
- white-space: pre;
- line-height: 18px;
+ font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
+ white-space: pre;
+ line-height: 18px;
}
@@ -36,77 +36,75 @@
--registry <REGISTRY> Registry to upload the package to
- --token <TOKEN> Token to use when uploading
+ --no-verify Don't verify the contents by building them
- --no-verify Don't verify the contents by building them
+ --allow-dirty Allow dirty working directories to be packaged
- --allow-dirty Allow dirty working directories to be packaged
+ -v, --verbose... Use verbose output (-vv very verbose/build.rs output)
- -v, --verbose... Use verbose output (-vv very verbose/build.rs output)
+ -q, --quiet Do not print cargo log messages
- -q, --quiet Do not print cargo log messages
+ --color <WHEN> Coloring [possible values: auto, always, never]
- --color <WHEN> Coloring [possible values: auto, always, never]
+ --config <KEY=VALUE|PATH> Override a configuration value
- --config <KEY=VALUE|PATH> Override a configuration value
+ -Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
- -Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
+ details
- details
+ -h, --help Print help
- -h, --help Print help
+
-
+ Package Selection:
- Package Selection:
+ -p, --package [<SPEC>] Package(s) to publish
- -p, --package [<SPEC>] Package(s) to publish
+ --workspace Publish all packages in the workspace
- --workspace Publish all packages in the workspace
+ --exclude <SPEC> Don't publish specified packages
- --exclude <SPEC> Don't publish specified packages
+
-
+ Feature Selection:
- Feature Selection:
+ -F, --features <FEATURES> Space or comma separated list of features to activate
- -F, --features <FEATURES> Space or comma separated list of features to activate
+ --all-features Activate all available features
- --all-features Activate all available features
+ --no-default-features Do not activate the `default` feature
- --no-default-features Do not activate the `default` feature
+
-
+ Compilation Options:
- Compilation Options:
+ -j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
- -j, --jobs <N> Number of parallel jobs, defaults to # of CPUs.
+ --keep-going Do not abort the build as soon as there is an error
- --keep-going Do not abort the build as soon as there is an error
+ --target [<TRIPLE>] Build for the target triple
- --target [<TRIPLE>] Build for the target triple
+ --target-dir <DIRECTORY> Directory for all generated artifacts
- --target-dir <DIRECTORY> Directory for all generated artifacts
+
-
+ Manifest Options:
- Manifest Options:
+ --manifest-path <PATH> Path to Cargo.toml
- --manifest-path <PATH> Path to Cargo.toml
+ --lockfile-path <PATH> Path to Cargo.lock (unstable)
- --lockfile-path <PATH> Path to Cargo.lock (unstable)
+ --locked Assert that `Cargo.lock` will remain unchanged
- --locked Assert that `Cargo.lock` will remain unchanged
+ --offline Run without accessing the network
- --offline Run without accessing the network
+ --frozen Equivalent to specifying both --locked and --offline
- --frozen Equivalent to specifying both --locked and --offline
+
-
+ Run `cargo help publish` for more detailed information.
- Run `cargo help publish` for more detailed information.
-
-
+
diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs
index c3da82a4aec..0d6cf0271b2 100644
--- a/tests/testsuite/publish.rs
+++ b/tests/testsuite/publish.rs
@@ -207,6 +207,7 @@ fn simple_publish_with_http() {
p.cargo("publish --no-verify --token sekrit --registry dummy-registry")
.with_stderr_data(str![[r#"
+[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
[UPDATING] `dummy-registry` index
[WARNING] manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
@@ -351,6 +352,7 @@ fn simple_with_index() {
.arg("--index")
.arg(registry.index_url().as_str())
.with_stderr_data(str![[r#"
+[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
[UPDATING] `[ROOT]/registry` index
[WARNING] manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.