Skip to content

Commit 7f0fdc3

Browse files
committed
feat(cli): Add --ignore-rust-version to update/generate-lockfile
1 parent 48ab82e commit 7f0fdc3

File tree

14 files changed

+97
-35
lines changed

14 files changed

+97
-35
lines changed

src/bin/cargo/commands/generate_lockfile.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@ pub fn cli() -> Command {
77
.about("Generate the lockfile for a package")
88
.arg_silent_suggestion()
99
.arg_manifest_path()
10+
.arg_ignore_rust_version_with_help(
11+
"Ignore `rust-version` specification in packages (unstable)",
12+
)
1013
.after_help(color_print::cstr!(
1114
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
1215
))
1316
}
1417

1518
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
19+
if args.honor_rust_version().is_some() {
20+
gctx.cli_unstable().fail_if_stable_opt_custom_z(
21+
"--ignore-rust-version",
22+
9930,
23+
"msrv-policy",
24+
gctx.cli_unstable().msrv_policy,
25+
)?;
26+
}
1627
let ws = args.workspace(gctx)?;
1728
ops::generate_lockfile(&ws)?;
1829
Ok(())

src/bin/cargo/commands/update.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,23 @@ pub fn cli() -> Command {
4242
.help_heading(heading::PACKAGE_SELECTION),
4343
)
4444
.arg_manifest_path()
45+
.arg_ignore_rust_version_with_help(
46+
"Ignore `rust-version` specification in packages (unstable)",
47+
)
4548
.after_help(color_print::cstr!(
4649
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
4750
))
4851
}
4952

5053
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
54+
if args.honor_rust_version().is_some() {
55+
gctx.cli_unstable().fail_if_stable_opt_custom_z(
56+
"--ignore-rust-version",
57+
9930,
58+
"msrv-policy",
59+
gctx.cli_unstable().msrv_policy,
60+
)?;
61+
}
5162
let ws = args.workspace(gctx)?;
5263

5364
if args.is_present_with_zero_values("package") {

src/cargo/util/command_prelude.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
352352
}
353353

354354
fn arg_ignore_rust_version(self) -> Self {
355-
self._arg(
356-
flag(
357-
"ignore-rust-version",
358-
"Ignore `rust-version` specification in packages",
359-
)
360-
.help_heading(heading::MANIFEST_OPTIONS),
361-
)
355+
self.arg_ignore_rust_version_with_help("Ignore `rust-version` specification in packages")
356+
}
357+
358+
fn arg_ignore_rust_version_with_help(self, help: &'static str) -> Self {
359+
self._arg(flag("ignore-rust-version", help).help_heading(heading::MANIFEST_OPTIONS))
362360
}
363361

364362
fn arg_future_incompat_report(self) -> Self {

src/doc/man/cargo-generate-lockfile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
3030
{{#options}}
3131
{{> options-manifest-path }}
3232

33+
{{> options-ignore-rust-version }}
34+
3335
{{> options-locked }}
3436
{{/options}}
3537

src/doc/man/cargo-update.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.
7575

7676
{{> options-manifest-path }}
7777

78+
{{> options-ignore-rust-version }}
79+
7880
{{> options-locked }}
7981

8082
{{/options}}

src/doc/man/generated_txt/cargo-generate-lockfile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ OPTIONS
4646
Path to the Cargo.toml file. By default, Cargo searches for the
4747
Cargo.toml file in the current directory or any parent directory.
4848

49+
--ignore-rust-version
50+
Ignore rust-version specification in packages.
51+
4952
--locked
5053
Asserts that the exact same dependencies and versions are used as
5154
when the existing Cargo.lock file was originally generated. Cargo

src/doc/man/generated_txt/cargo-update.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ OPTIONS
8585
Path to the Cargo.toml file. By default, Cargo searches for the
8686
Cargo.toml file in the current directory or any parent directory.
8787

88+
--ignore-rust-version
89+
Ignore rust-version specification in packages.
90+
8891
--locked
8992
Asserts that the exact same dependencies and versions are used as
9093
when the existing Cargo.lock file was originally generated. Cargo

src/doc/src/commands/cargo-generate-lockfile.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ terminal.</li>
5858
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
5959

6060

61+
<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>
62+
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
63+
64+
6165
<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>
6266
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
6367
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

src/doc/src/commands/cargo-update.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ terminal.</li>
100100
<code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
101101

102102

103+
<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>
104+
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>
105+
106+
103107
<dt class="option-term" id="option-cargo-update---locked"><a class="option-anchor" href="#option-cargo-update---locked"></a><code>--locked</code></dt>
104108
<dd class="option-desc">Asserts that the exact same dependencies and versions are used as when the
105109
existing <code>Cargo.lock</code> file was originally generated. Cargo will exit with an

src/etc/man/cargo-generate-lockfile.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
6262
\fBCargo.toml\fR file in the current directory or any parent directory.
6363
.RE
6464
.sp
65+
\fB\-\-ignore\-rust\-version\fR
66+
.RS 4
67+
Ignore \fBrust\-version\fR specification in packages.
68+
.RE
69+
.sp
6570
\fB\-\-locked\fR
6671
.RS 4
6772
Asserts that the exact same dependencies and versions are used as when the

src/etc/man/cargo-update.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ Path to the \fBCargo.toml\fR file. By default, Cargo searches for the
107107
\fBCargo.toml\fR file in the current directory or any parent directory.
108108
.RE
109109
.sp
110+
\fB\-\-ignore\-rust\-version\fR
111+
.RS 4
112+
Ignore \fBrust\-version\fR specification in packages.
113+
.RE
114+
.sp
110115
\fB\-\-locked\fR
111116
.RS 4
112117
Asserts that the exact same dependencies and versions are used as when the

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

Lines changed: 9 additions & 7 deletions
Loading

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

Lines changed: 9 additions & 7 deletions
Loading

tests/testsuite/rust_version.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,23 @@ fn generate_lockfile_msrv_resolve() {
532532
.file("src/main.rs", "fn main(){}")
533533
.build();
534534

535+
p.cargo("generate-lockfile --ignore-rust-version")
536+
.with_status(101)
537+
.with_stderr(
538+
"\
539+
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
540+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
541+
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
542+
",
543+
)
544+
.run();
535545
p.cargo("generate-lockfile --ignore-rust-version")
536546
.arg("-Zmsrv-policy")
537547
.masquerade_as_nightly_cargo(&["msrv-policy"])
538-
.with_status(1)
539548
.with_stderr(
540549
"\
541-
error: unexpected argument '--ignore-rust-version' found
542-
543-
Usage: cargo generate-lockfile [OPTIONS]
544-
545-
For more information, try '--help'.
550+
[UPDATING] `dummy-registry` index
551+
[LOCKING] 2 packages
546552
",
547553
)
548554
.run();
@@ -595,22 +601,26 @@ fn update_msrv_resolve() {
595601
[UPDATING] `dummy-registry` index
596602
[LOCKING] 2 packages
597603
[ADDING] bar v1.5.0 (latest: v1.6.0)
604+
",
605+
)
606+
.run();
607+
p.cargo("update --ignore-rust-version")
608+
.with_status(101)
609+
.with_stderr(
610+
"\
611+
[ERROR] the `--ignore-rust-version` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
612+
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
613+
See https://github.com/rust-lang/cargo/issues/9930 for more information about the `--ignore-rust-version` flag.
598614
",
599615
)
600616
.run();
601617
p.cargo("update --ignore-rust-version")
602618
.arg("-Zmsrv-policy")
603619
.masquerade_as_nightly_cargo(&["msrv-policy"])
604-
.with_status(1)
605620
.with_stderr(
606621
"\
607-
error: unexpected argument '--ignore-rust-version' found
608-
609-
tip: to pass '--ignore-rust-version' as a value, use '-- --ignore-rust-version'
610-
611-
Usage: cargo update [OPTIONS] [SPEC]...
612-
613-
For more information, try '--help'.
622+
[UPDATING] `dummy-registry` index
623+
[UPDATING] bar v1.5.0 -> v1.6.0
614624
",
615625
)
616626
.run();

0 commit comments

Comments
 (0)