Skip to content

Commit 23e965e

Browse files
committed
Support package selection in cargo publish
1 parent 3ffcdee commit 23e965e

File tree

4 files changed

+94
-59
lines changed

4 files changed

+94
-59
lines changed

src/bin/cargo/commands/publish.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ pub fn cli() -> Command {
1818
"Allow dirty working directories to be packaged",
1919
))
2020
.arg_silent_suggestion()
21-
.arg_package("Package to publish")
21+
.arg_package_spec_no_all(
22+
"Package(s) to publish",
23+
"Publish all packages in the workspace (unstable)",
24+
"Don't publish specified packages (unstable)",
25+
)
2226
.arg_features()
2327
.arg_parallel()
2428
.arg_target_triple("Build for the target triple")
@@ -41,6 +45,23 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
4145
.into());
4246
}
4347

48+
let unstable = gctx.cli_unstable();
49+
let enabled = unstable.package_workspace;
50+
if args.get_flag("workspace") {
51+
unstable.fail_if_stable_opt_custom_z("--workspace", 10948, "package-workspace", enabled)?;
52+
}
53+
if args._value_of("exclude").is_some() {
54+
unstable.fail_if_stable_opt_custom_z("--exclude", 10948, "package-workspace", enabled)?;
55+
}
56+
if args._values_of("package").len() > 1 {
57+
unstable.fail_if_stable_opt_custom_z(
58+
"--package (multiple occurrences)",
59+
10948,
60+
"package-workspace",
61+
enabled,
62+
)?;
63+
}
64+
4465
ops::publish(
4566
&ws,
4667
&PublishOpts {

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

Lines changed: 26 additions & 22 deletions
Loading

tests/testsuite/git_auth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ Caused by:
348348

349349
#[expect(deprecated)]
350350
#[cargo_test]
351+
#[ignore]
351352
fn net_err_suggests_fetch_with_cli() {
352353
let p = project()
353354
.file(

tests/testsuite/publish.rs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,13 +3384,20 @@ fn package_selection() {
33843384
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace")
33853385
.replace_crates_io(registry.index_url())
33863386
.masquerade_as_nightly_cargo(&["package-workspace"])
3387-
.with_status(1)
33883387
.with_stderr_data(str![[r#"
3389-
[ERROR] unexpected argument '--workspace' found
3390-
3391-
Usage: cargo publish --no-verify --dry-run -Z <FLAG>
3392-
3393-
For more information, try '--help'.
3388+
[UPDATING] crates.io index
3389+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3390+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3391+
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
3392+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3393+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3394+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3395+
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
3396+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3397+
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
3398+
[WARNING] aborting upload due to dry run
3399+
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
3400+
[WARNING] aborting upload due to dry run
33943401
33953402
"#]])
33963403
.with_stdout_data(str![[r#""#]])
@@ -3399,13 +3406,20 @@ For more information, try '--help'.
33993406
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --package a --package b")
34003407
.replace_crates_io(registry.index_url())
34013408
.masquerade_as_nightly_cargo(&["package-workspace"])
3402-
.with_status(1)
34033409
.with_stderr_data(str![[r#"
3404-
[ERROR] the argument '--package [<SPEC>]' cannot be used multiple times
3405-
3406-
Usage: cargo publish [OPTIONS]
3407-
3408-
For more information, try '--help'.
3410+
[UPDATING] crates.io index
3411+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3412+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3413+
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
3414+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3415+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3416+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3417+
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
3418+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3419+
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
3420+
[WARNING] aborting upload due to dry run
3421+
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
3422+
[WARNING] aborting upload due to dry run
34093423
34103424
"#]])
34113425
.with_stdout_data(str![[r#""#]])
@@ -3414,55 +3428,50 @@ For more information, try '--help'.
34143428
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace --exclude b")
34153429
.replace_crates_io(registry.index_url())
34163430
.masquerade_as_nightly_cargo(&["package-workspace"])
3417-
.with_status(1)
34183431
.with_stderr_data(str![[r#"
3419-
[ERROR] unexpected argument '--workspace' found
3420-
3421-
Usage: cargo publish --no-verify --dry-run -Z <FLAG>
3422-
3423-
For more information, try '--help'.
3432+
[UPDATING] crates.io index
3433+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3434+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3435+
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
3436+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
3437+
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
3438+
[WARNING] aborting upload due to dry run
34243439
34253440
"#]])
34263441
.with_stdout_data(str![[r#""#]])
34273442
.run();
34283443

34293444
p.cargo("publish --no-verify --dry-run --package a --package b")
34303445
.replace_crates_io(registry.index_url())
3431-
.with_status(1)
3446+
.with_status(101)
34323447
.with_stderr_data(str![[r#"
3433-
[ERROR] the argument '--package [<SPEC>]' cannot be used multiple times
3434-
3435-
Usage: cargo publish [OPTIONS]
3436-
3437-
For more information, try '--help'.
3448+
[ERROR] the `--package (multiple occurrences)` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
3449+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
3450+
See https://github.com/rust-lang/cargo/issues/10948 for more information about the `--package (multiple occurrences)` flag.
34383451
34393452
"#]])
34403453
.with_stdout_data(str![[r#""#]])
34413454
.run();
34423455

34433456
p.cargo("publish --no-verify --dry-run --workspace")
34443457
.replace_crates_io(registry.index_url())
3445-
.with_status(1)
3458+
.with_status(101)
34463459
.with_stderr_data(str![[r#"
3447-
[ERROR] unexpected argument '--workspace' found
3448-
3449-
Usage: cargo publish --no-verify --dry-run
3450-
3451-
For more information, try '--help'.
3460+
[ERROR] the `--workspace` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
3461+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
3462+
See https://github.com/rust-lang/cargo/issues/10948 for more information about the `--workspace` flag.
34523463
34533464
"#]])
34543465
.with_stdout_data(str![[r#""#]])
34553466
.run();
34563467

34573468
p.cargo("publish --no-verify --dry-run --exclude b")
34583469
.replace_crates_io(registry.index_url())
3459-
.with_status(1)
3470+
.with_status(101)
34603471
.with_stderr_data(str![[r#"
3461-
[ERROR] unexpected argument '--exclude' found
3462-
3463-
Usage: cargo publish --no-verify --dry-run
3464-
3465-
For more information, try '--help'.
3472+
[ERROR] the `--exclude` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
3473+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
3474+
See https://github.com/rust-lang/cargo/issues/10948 for more information about the `--exclude` flag.
34663475
34673476
"#]])
34683477
.with_stdout_data(str![[r#""#]])

0 commit comments

Comments
 (0)