Skip to content

Commit 12caaff

Browse files
committed
Auto merge of #14659 - tweag:publish-workspace-cli-args, r=<try>
Support package selection options like `--exclude` in `cargo publish` Fixes #14652. Is there a way to make the help text depend on whether nightly/unstable features are enabled? I couldn't find one...
2 parents 15fbd2f + 3e1a989 commit 12caaff

File tree

3 files changed

+119
-23
lines changed

3 files changed

+119
-23
lines changed

src/bin/cargo/commands/publish.rs

Lines changed: 5 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 (requires nightly)",
24+
"Don't publish specified packages (requires nightly)",
25+
)
2226
.arg_features()
2327
.arg_parallel()
2428
.arg_target_triple("Build for the target triple")

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

Lines changed: 26 additions & 22 deletions
Loading

tests/testsuite/publish.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,94 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
33643364
.run();
33653365
}
33663366

3367+
#[cargo_test]
3368+
fn package_selection() {
3369+
let registry = registry::RegistryBuilder::new().http_api().build();
3370+
let p = project()
3371+
.file(
3372+
"Cargo.toml",
3373+
r#"
3374+
[workspace]
3375+
members = ["a", "b"]
3376+
"#,
3377+
)
3378+
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
3379+
.file("a/src/lib.rs", "#[test] fn a() {}")
3380+
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
3381+
.file("b/src/lib.rs", "#[test] fn b() {}")
3382+
.build();
3383+
3384+
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace")
3385+
.replace_crates_io(registry.index_url())
3386+
.masquerade_as_nightly_cargo(&["package-workspace"])
3387+
.with_stderr_data(str![[r#"
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
3401+
3402+
"#]])
3403+
.with_stdout_data(str![[r#""#]])
3404+
.run();
3405+
3406+
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --package a --package b")
3407+
.replace_crates_io(registry.index_url())
3408+
.masquerade_as_nightly_cargo(&["package-workspace"])
3409+
.with_stderr_data(str![[r#"
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
3423+
3424+
"#]])
3425+
.with_stdout_data(str![[r#""#]])
3426+
.run();
3427+
3428+
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace --exclude b")
3429+
.replace_crates_io(registry.index_url())
3430+
.masquerade_as_nightly_cargo(&["package-workspace"])
3431+
.with_stderr_data(str![[r#"
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
3439+
3440+
"#]])
3441+
.with_stdout_data(str![[r#""#]])
3442+
.run();
3443+
3444+
p.cargo("publish --no-verify --dry-run --package a --package b")
3445+
.replace_crates_io(registry.index_url())
3446+
.with_status(101)
3447+
.with_stderr_data(str![[r#"
3448+
[ERROR] the `-p` argument must be specified to select a single package to publish
3449+
3450+
"#]])
3451+
.with_stdout_data(str![[r#""#]])
3452+
.run();
3453+
}
3454+
33673455
#[cargo_test]
33683456
fn wait_for_git_publish() {
33693457
// Slow publish to an index with a git index.

0 commit comments

Comments
 (0)