Skip to content

Commit

Permalink
Support package-selection arguments in cargo publish
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Oct 9, 2024
1 parent 45565f8 commit 3e1a989
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 47 deletions.
6 changes: 5 additions & 1 deletion src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pub fn cli() -> Command {
"Allow dirty working directories to be packaged",
))
.arg_silent_suggestion()
.arg_package("Package to publish")
.arg_package_spec_no_all(
"Package(s) to publish",
"Publish all packages in the workspace (requires nightly)",
"Don't publish specified packages (requires nightly)",
)
.arg_features()
.arg_parallel()
.arg_target_triple("Build for the target triple")
Expand Down
48 changes: 26 additions & 22 deletions tests/testsuite/cargo_publish/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 35 additions & 24 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3384,13 +3384,20 @@ fn package_selection() {
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(1)
.with_stderr_data(str![[r#"
[ERROR] unexpected argument '--workspace' found
Usage: cargo publish --no-verify --dry-run -Z <FLAG>
For more information, try '--help'.
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
Expand All @@ -3399,13 +3406,20 @@ For more information, try '--help'.
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --package a --package b")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(1)
.with_stderr_data(str![[r#"
[ERROR] the argument '--package [<SPEC>]' cannot be used multiple times
Usage: cargo publish [OPTIONS]
For more information, try '--help'.
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] b v0.1.0 ([ROOT]/foo/b)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
[UPLOADING] b v0.1.0 ([ROOT]/foo/b)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
Expand All @@ -3414,27 +3428,24 @@ For more information, try '--help'.
p.cargo("publish --no-verify --dry-run -Zpackage-workspace --workspace --exclude b")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["package-workspace"])
.with_status(1)
.with_stderr_data(str![[r#"
[ERROR] unexpected argument '--workspace' found
Usage: cargo publish --no-verify --dry-run -Z <FLAG>
For more information, try '--help'.
[UPDATING] crates.io index
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[PACKAGING] a v0.1.0 ([ROOT]/foo/a)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] a v0.1.0 ([ROOT]/foo/a)
[WARNING] aborting upload due to dry run
"#]])
.with_stdout_data(str![[r#""#]])
.run();

p.cargo("publish --no-verify --dry-run --package a --package b")
.replace_crates_io(registry.index_url())
.with_status(1)
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the argument '--package [<SPEC>]' cannot be used multiple times
Usage: cargo publish [OPTIONS]
For more information, try '--help'.
[ERROR] the `-p` argument must be specified to select a single package to publish
"#]])
.with_stdout_data(str![[r#""#]])
Expand Down

0 comments on commit 3e1a989

Please sign in to comment.