Skip to content

Commit 6efd504

Browse files
committed
feat (publish): deprecate --token option with warning
1 parent 5b48cf2 commit 6efd504

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

src/bin/cargo/commands/publish.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
use crate::command_prelude::*;
22

33
use cargo::ops::{self, PublishOpts};
4+
use cargo_credential::Secret;
45

56
pub fn cli() -> Command {
67
subcommand("publish")
78
.about("Upload a package to the registry")
89
.arg_dry_run("Perform all checks without uploading")
910
.arg_index("Registry index URL to upload the package to")
1011
.arg_registry("Registry to upload the package to")
11-
.arg(opt("token", "Token to use when uploading").value_name("TOKEN"))
12+
.arg(
13+
opt("token", "Token to use when uploading")
14+
.value_name("TOKEN")
15+
.hide(true),
16+
)
1217
.arg(flag(
1318
"no-verify",
1419
"Don't verify the contents by building them",
@@ -45,13 +50,16 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
4550
.into());
4651
}
4752

53+
let token = args.get_one::<String>("token").cloned().map(Secret::from);
54+
if token.is_some() {
55+
let _ = gctx.shell().warn("`cargo publish --token` is deprecated in favor of using `cargo login` and environment variables");
56+
}
57+
4858
ops::publish(
4959
&ws,
5060
&PublishOpts {
5161
gctx,
52-
token: args
53-
.get_one::<String>("token")
54-
.map(|s| s.to_string().into()),
62+
token,
5563
reg_or_index,
5664
verify: !args.flag("no-verify"),
5765
allow_dirty: args.flag("allow-dirty"),

tests/testsuite/alt_registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ Caused by:
306306
.arg(crates_io.index_url().as_str())
307307
.with_status(101)
308308
.with_stderr_data(str![[r#"
309+
[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
309310
[UPDATING] crates.io index
310311
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
311312

tests/testsuite/cargo_publish/help/stdout.term.svg

Lines changed: 40 additions & 42 deletions
Loading

tests/testsuite/publish.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ fn simple_publish_with_http() {
207207

208208
p.cargo("publish --no-verify --token sekrit --registry dummy-registry")
209209
.with_stderr_data(str![[r#"
210+
[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
210211
[UPDATING] `dummy-registry` index
211212
[WARNING] manifest has no documentation, homepage or repository.
212213
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
@@ -351,6 +352,7 @@ fn simple_with_index() {
351352
.arg("--index")
352353
.arg(registry.index_url().as_str())
353354
.with_stderr_data(str![[r#"
355+
[WARNING] `cargo publish --token` is deprecated in favor of using `cargo login` and environment variables
354356
[UPDATING] `[ROOT]/registry` index
355357
[WARNING] manifest has no documentation, homepage or repository.
356358
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.

0 commit comments

Comments
 (0)