feat(cli): Add --ignore-rust-version to update/generate-lockfile

This commit is contained in:
Ed Page 2024-04-11 14:27:57 -05:00
parent c9de6eeeb2
commit c7d89c64f1
14 changed files with 101 additions and 39 deletions

View File

@ -7,12 +7,23 @@ pub fn cli() -> Command {
.about("Generate the lockfile for a package") .about("Generate the lockfile for a package")
.arg_silent_suggestion() .arg_silent_suggestion()
.arg_manifest_path() .arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!( .after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n" "Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
)) ))
} }
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let ws = args.workspace(gctx)?; let ws = args.workspace(gctx)?;
ops::generate_lockfile(&ws)?; ops::generate_lockfile(&ws)?;
Ok(()) Ok(())

View File

@ -42,12 +42,23 @@ pub fn cli() -> Command {
.help_heading(heading::PACKAGE_SELECTION), .help_heading(heading::PACKAGE_SELECTION),
) )
.arg_manifest_path() .arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!( .after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n" "Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
)) ))
} }
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args.honor_rust_version().is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--ignore-rust-version",
9930,
"msrv-policy",
gctx.cli_unstable().msrv_policy,
)?;
}
let ws = args.workspace(gctx)?; let ws = args.workspace(gctx)?;
if args.is_present_with_zero_values("package") { if args.is_present_with_zero_values("package") {

View File

@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
} }
fn arg_ignore_rust_version(self) -> Self { fn arg_ignore_rust_version(self) -> Self {
self._arg( self.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
flag( }
"ignore-rust-version",
"Ignore `rust-version` specification in packages", fn arg_ignore_rust_version_with_help(self, help: &'static str) -> Self {
) self._arg(flag("ignore-rust-version", help).help_heading(heading::MANIFEST_OPTIONS))
.help_heading(heading::MANIFEST_OPTIONS),
)
} }
fn arg_future_incompat_report(self) -> Self { fn arg_future_incompat_report(self) -> Self {

View File

@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
{{#options}} {{#options}}
{{> options-manifest-path }} {{> options-manifest-path }}
{{> options-ignore-rust-version }}
{{> options-locked }} {{> options-locked }}
{{/options}} {{/options}}

View File

@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.
{{> options-manifest-path }} {{> options-manifest-path }}
{{> options-ignore-rust-version }}
{{> options-locked }} {{> options-locked }}
{{/options}} {{/options}}

View File

@ -46,6 +46,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory. Cargo.toml file in the current directory or any parent directory.
--ignore-rust-version
Ignore rust-version specification in packages.
--locked --locked
Asserts that the exact same dependencies and versions are used as Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo when the existing Cargo.lock file was originally generated. Cargo

View File

@ -85,6 +85,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory. Cargo.toml file in the current directory or any parent directory.
--ignore-rust-version
Ignore rust-version specification in packages.
--locked --locked
Asserts that the exact same dependencies and versions are used as Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo when the existing Cargo.lock file was originally generated. Cargo

View File

@ -58,6 +58,10 @@ terminal.</li>
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd> <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
<dt class="option-term" id="option-cargo-generate-lockfile---ignore-rust-version"><a class="option-anchor" href="#option-cargo-generate-lockfile---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
<dt class="option-term" id="option-cargo-generate-lockfile---locked"><a class="option-anchor" href="#option-cargo-generate-lockfile---locked"></a><code>--locked</code></dt> <dt class="option-term" id="option-cargo-generate-lockfile---locked"><a class="option-anchor" href="#option-cargo-generate-lockfile---locked"></a><code>--locked</code></dt>
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the <dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

View File

@ -100,6 +100,10 @@ terminal.</li>
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd> <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
<dt class="option-term" id="option-cargo-update---ignore-rust-version"><a class="option-anchor" href="#option-cargo-update---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
<dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt> <dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt>
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the <dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

View File

@ -62,6 +62,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
\fBCargo.toml\fR file in the current directory or any parent directory. \fBCargo.toml\fR file in the current directory or any parent directory.
.RE .RE
.sp .sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR \fB\-\-locked\fR
.RS 4 .RS 4
Asserts that the exact same dependencies and versions are used as when the Asserts that the exact same dependencies and versions are used as when the

View File

@ -107,6 +107,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
\fBCargo.toml\fR file in the current directory or any parent directory. \fBCargo.toml\fR file in the current directory or any parent directory.
.RE .RE
.sp .sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR \fB\-\-locked\fR
.RS 4 .RS 4
Asserts that the exact same dependencies and versions are used as when the Asserts that the exact same dependencies and versions are used as when the

View File

@ -1,4 +1,4 @@
<svg width="852px" height="380px" xmlns="http://www.w3.org/2000/svg"> <svg width="852px" height="398px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -47,17 +47,19 @@
</tspan> </tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan> <tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
</tspan> </tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan> <tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
</tspan> </tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan> <tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan> </tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan> <tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
</tspan> </tspan>
<tspan x="10px" y="334px"> <tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan>
</tspan> </tspan>
<tspan x="10px" y="352px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help generate-lockfile</tspan><tspan class="bold">` for more detailed information.</tspan> <tspan x="10px" y="352px">
</tspan> </tspan>
<tspan x="10px" y="370px"> <tspan x="10px" y="370px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help generate-lockfile</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="388px">
</tspan> </tspan>
</text> </text>

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1,4 +1,4 @@
<svg width="852px" height="506px" xmlns="http://www.w3.org/2000/svg"> <svg width="852px" height="524px" xmlns="http://www.w3.org/2000/svg">
<style> <style>
.fg { fill: #AAAAAA } .fg { fill: #AAAAAA }
.bg { background: #000000 } .bg { background: #000000 }
@ -61,17 +61,19 @@
</tspan> </tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan> <tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
</tspan> </tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan> <tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">--ignore-rust-version</tspan><tspan> Ignore `rust-version` specification in packages (unstable)</tspan>
</tspan> </tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan> <tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Assert that `Cargo.lock` will remain unchanged</tspan>
</tspan> </tspan>
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan> <tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
</tspan> </tspan>
<tspan x="10px" y="460px"> <tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Equivalent to specifying both --locked and --offline</tspan>
</tspan> </tspan>
<tspan x="10px" y="478px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help update</tspan><tspan class="bold">` for more detailed information.</tspan> <tspan x="10px" y="478px">
</tspan> </tspan>
<tspan x="10px" y="496px"> <tspan x="10px" y="496px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help update</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="514px">
</tspan> </tspan>
</text> </text>

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -533,16 +533,22 @@ fn generate_lockfile_msrv_resolve() {
.build(); .build();
p.cargo("generate-lockfile --ignore-rust-version") p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy") .with_status(101)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_status(1)
.with_stderr( .with_stderr(
"\ "\
error: unexpected argument '--ignore-rust-version' found [ERROR] the `--ignore-rust-version` 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.
Usage: cargo generate-lockfile [OPTIONS] See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
",
For more information, try '--help'. )
.run();
p.cargo("generate-lockfile --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages
", ",
) )
.run(); .run();
@ -599,18 +605,22 @@ fn update_msrv_resolve() {
) )
.run(); .run();
p.cargo("update --ignore-rust-version") p.cargo("update --ignore-rust-version")
.arg("-Zmsrv-policy") .with_status(101)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_status(1)
.with_stderr( .with_stderr(
"\ "\
error: unexpected argument '--ignore-rust-version' found [ERROR] the `--ignore-rust-version` 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.
tip: to pass '--ignore-rust-version' as a value, use '-- --ignore-rust-version' See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
",
Usage: cargo update [OPTIONS] [SPEC]... )
.run();
For more information, try '--help'. p.cargo("update --ignore-rust-version")
.arg("-Zmsrv-policy")
.masquerade_as_nightly_cargo(&["msrv-policy"])
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[UPDATING] bar v1.5.0 -> v1.6.0
", ",
) )
.run(); .run();