Skip to content

Commit

Permalink
Support package selection in cargo publish
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Oct 10, 2024
1 parent 3ffcdee commit 23e965e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 59 deletions.
23 changes: 22 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 (unstable)",
"Don't publish specified packages (unstable)",
)
.arg_features()
.arg_parallel()
.arg_target_triple("Build for the target triple")
Expand All @@ -41,6 +45,23 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
.into());
}

let unstable = gctx.cli_unstable();
let enabled = unstable.package_workspace;
if args.get_flag("workspace") {
unstable.fail_if_stable_opt_custom_z("--workspace", 10948, "package-workspace", enabled)?;
}
if args._value_of("exclude").is_some() {
unstable.fail_if_stable_opt_custom_z("--exclude", 10948, "package-workspace", enabled)?;
}
if args._values_of("package").len() > 1 {
unstable.fail_if_stable_opt_custom_z(
"--package (multiple occurrences)",
10948,
"package-workspace",
enabled,
)?;
}

ops::publish(
&ws,
&PublishOpts {
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.
1 change: 1 addition & 0 deletions tests/testsuite/git_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ Caused by:

#[expect(deprecated)]
#[cargo_test]
#[ignore]
fn net_err_suggests_fetch_with_cli() {
let p = project()
.file(
Expand Down
81 changes: 45 additions & 36 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,55 +3428,50 @@ 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 `--package (multiple occurrences)` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/10948 for more information about the `--package (multiple occurrences)` flag.
"#]])
.with_stdout_data(str![[r#""#]])
.run();

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

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

0 comments on commit 23e965e

Please sign in to comment.