Skip to content

Commit

Permalink
Auto merge of #14659 - tweag:publish-workspace-cli-args, r=weihanglo
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
bors committed Oct 15, 2024
2 parents f9e20ff + d30fde9 commit 5b220de
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 42 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
59 changes: 58 additions & 1 deletion src/doc/man/cargo-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,64 @@ which defaults to `crates-io`.

{{/options}}

{{> section-options-package }}
### Package Selection

By default, when no package selection options are given, the packages selected
depend on the selected manifest file (based on the current working directory if
`--manifest-path` is not given). If the manifest is the root of a workspace then
the workspaces default members are selected, otherwise only the package defined
by the manifest will be selected.

The default members of a workspace can be set explicitly with the
`workspace.default-members` key in the root manifest. If this is not set, a
virtual workspace will include all workspace members (equivalent to passing
`--workspace`), and a non-virtual workspace will include only the root crate itself.

Selecting more than one package is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.


{{#options}}

{{#option "`-p` _spec_..." "`--package` _spec_..."}}
{{actionverb}} only the specified packages. See {{man "cargo-pkgid" 1}} for the
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like `*`, `?` and `[]`. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.
{{/option}}

Selecting more than one package with this option is unstable and available only
on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.

{{#option "`--workspace`" }}
{{actionverb}} all members in the workspace.

This option is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
{{/option}}

{{#option "`--exclude` _SPEC_..." }}
Exclude the specified packages. Must be used in conjunction with the
`--workspace` flag. This flag may be specified multiple times and supports
common Unix glob patterns like `*`, `?` and `[]`. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.

This option is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
{{/option}}

{{/options}}

### Compilation Options

Expand Down
62 changes: 58 additions & 4 deletions src/doc/man/generated_txt/cargo-publish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,65 @@ OPTIONS
config key which defaults to crates-io.

Package Selection
By default, the package in the current working directory is selected.
The -p flag can be used to choose a different package in a workspace.
By default, when no package selection options are given, the packages
selected depend on the selected manifest file (based on the current
working directory if --manifest-path is not given). If the manifest is
the root of a workspace then the workspaces default members are
selected, otherwise only the package defined by the manifest will be
selected.

-p spec, --package spec
The package to publish. See cargo-pkgid(1) for the SPEC format.
The default members of a workspace can be set explicitly with the
workspace.default-members key in the root manifest. If this is not set,
a virtual workspace will include all workspace members (equivalent to
passing --workspace), and a non-virtual workspace will include only the
root crate itself.

Selecting more than one package is unstable and available only on the
nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more information.

-p spec…, --package spec…
Publish only the specified packages. See cargo-pkgid(1) for the SPEC
format. This flag may be specified multiple times and supports
common Unix glob patterns like *, ? and []. However, to avoid your
shell accidentally expanding glob patterns before Cargo handles
them, you must use single quotes or double quotes around each
pattern.

Selecting more than one package with this option is unstable and available only

on the

[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)

and requires the `-Z package-workspace` flag to enable.

See <https://github.com/rust-lang/cargo/issues/10948> for more information.

--workspace
Publish all members in the workspace.

This option is unstable and available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more
information.

--exclude SPEC…
Exclude the specified packages. Must be used in conjunction with the
--workspace flag. This flag may be specified multiple times and
supports common Unix glob patterns like *, ? and []. However, to
avoid your shell accidentally expanding glob patterns before Cargo
handles them, you must use single quotes or double quotes around
each pattern.

This option is unstable and available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more
information.

Compilation Options
--target triple
Expand Down
55 changes: 49 additions & 6 deletions src/doc/src/commands/cargo-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,58 @@ which defaults to <code>crates-io</code>.</dd>

### Package Selection

By default, the package in the current working directory is selected. The `-p`
flag can be used to choose a different package in a workspace.
By default, when no package selection options are given, the packages selected
depend on the selected manifest file (based on the current working directory if
`--manifest-path` is not given). If the manifest is the root of a workspace then
the workspaces default members are selected, otherwise only the package defined
by the manifest will be selected.

The default members of a workspace can be set explicitly with the
`workspace.default-members` key in the root manifest. If this is not set, a
virtual workspace will include all workspace members (equivalent to passing
`--workspace`), and a non-virtual workspace will include only the root crate itself.

Selecting more than one package is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.


<dl>

<dt class="option-term" id="option-cargo-publish--p"><a class="option-anchor" href="#option-cargo-publish--p"></a><code>-p</code> <em>spec</em></dt>
<dt class="option-term" id="option-cargo-publish---package"><a class="option-anchor" href="#option-cargo-publish---package"></a><code>--package</code> <em>spec</em></dt>
<dd class="option-desc">The package to publish. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the SPEC
format.</dd>
<dt class="option-term" id="option-cargo-publish--p"><a class="option-anchor" href="#option-cargo-publish--p"></a><code>-p</code> <em>spec</em>…</dt>
<dt class="option-term" id="option-cargo-publish---package"><a class="option-anchor" href="#option-cargo-publish---package"></a><code>--package</code> <em>spec</em>…</dt>
<dd class="option-desc">Publish only the specified packages. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.</dd>


Selecting more than one package with this option is unstable and available only
on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.

<dt class="option-term" id="option-cargo-publish---workspace"><a class="option-anchor" href="#option-cargo-publish---workspace"></a><code>--workspace</code></dt>
<dd class="option-desc">Publish all members in the workspace.</p>
<p>This option is unstable and available only on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z package-workspace</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/10948">https://github.com/rust-lang/cargo/issues/10948</a> for more information.</dd>


<dt class="option-term" id="option-cargo-publish---exclude"><a class="option-anchor" href="#option-cargo-publish---exclude"></a><code>--exclude</code> <em>SPEC</em>…</dt>
<dd class="option-desc">Exclude the specified packages. Must be used in conjunction with the
<code>--workspace</code> flag. This flag may be specified multiple times and supports
common Unix glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.</p>
<p>This option is unstable and available only on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z package-workspace</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/10948">https://github.com/rust-lang/cargo/issues/10948</a> for more information.</dd>


</dl>
Expand Down
61 changes: 53 additions & 8 deletions src/etc/man/cargo-publish.1
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,59 @@ Otherwise it will use the default registry, which is defined by the
which defaults to \fBcrates\-io\fR\&.
.RE
.SS "Package Selection"
By default, the package in the current working directory is selected. The \fB\-p\fR
flag can be used to choose a different package in a workspace.
.sp
\fB\-p\fR \fIspec\fR,
\fB\-\-package\fR \fIspec\fR
.RS 4
The package to publish. See \fBcargo\-pkgid\fR(1) for the SPEC
format.
By default, when no package selection options are given, the packages selected
depend on the selected manifest file (based on the current working directory if
\fB\-\-manifest\-path\fR is not given). If the manifest is the root of a workspace then
the workspaces default members are selected, otherwise only the package defined
by the manifest will be selected.
.sp
The default members of a workspace can be set explicitly with the
\fBworkspace.default\-members\fR key in the root manifest. If this is not set, a
virtual workspace will include all workspace members (equivalent to passing
\fB\-\-workspace\fR), and a non\-virtual workspace will include only the root crate itself.
.sp
Selecting more than one package is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.sp
\fB\-p\fR \fIspec\fR\[u2026],
\fB\-\-package\fR \fIspec\fR\[u2026]
.RS 4
Publish only the specified packages. See \fBcargo\-pkgid\fR(1) for the
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.
.RE
Selecting more than one package with this option is unstable and available only
on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
.sp
\fB\-\-workspace\fR
.RS 4
Publish all members in the workspace.
.sp
This option is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.RE
.sp
\fB\-\-exclude\fR \fISPEC\fR\[u2026]
.RS 4
Exclude the specified packages. Must be used in conjunction with the
\fB\-\-workspace\fR flag. This flag may be specified multiple times and supports
common Unix glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.
.sp
This option is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.RE
.SS "Compilation Options"
.sp
Expand Down
Loading

0 comments on commit 5b220de

Please sign in to comment.