Skip to content

Commit

Permalink
feat(cli): Add --ignore-rust-version to update/generate-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 11, 2024
1 parent c9de6ee commit c7d89c6
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 35 deletions.
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ pub fn cli() -> Command {
.about("Generate the lockfile for a package")
.arg_silent_suggestion()
.arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"
))
}

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)?;
ops::generate_lockfile(&ws)?;
Ok(())
Expand Down
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ pub fn cli() -> Command {
.help_heading(heading::PACKAGE_SELECTION),
)
.arg_manifest_path()
.arg_ignore_rust_version_with_help(
"Ignore `rust-version` specification in packages (unstable)",
)
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help update</>` for more detailed information.\n"
))
}

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)?;

if args.is_present_with_zero_values("package") {
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,11 @@ pub trait CommandExt: Sized {
}

fn arg_ignore_rust_version(self) -> Self {
self._arg(
flag(
"ignore-rust-version",
"Ignore `rust-version` specification in packages",
)
.help_heading(heading::MANIFEST_OPTIONS),
)
self.arg_ignore_rust_version_with_help("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))
}

fn arg_future_incompat_report(self) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-generate-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ lockfile and has more options for controlling update behavior.
{{#options}}
{{> options-manifest-path }}

{{> options-ignore-rust-version }}

{{> options-locked }}
{{/options}}

Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Displays what would be updated, but doesn't actually write the lockfile.

{{> options-manifest-path }}

{{> options-ignore-rust-version }}

{{> options-locked }}

{{/options}}
Expand Down
3 changes: 3 additions & 0 deletions src/doc/man/generated_txt/cargo-generate-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory.

--ignore-rust-version
Ignore rust-version specification in packages.

--locked
Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo
Expand Down
3 changes: 3 additions & 0 deletions src/doc/man/generated_txt/cargo-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ OPTIONS
Path to the Cargo.toml file. By default, Cargo searches for the
Cargo.toml file in the current directory or any parent directory.

--ignore-rust-version
Ignore rust-version specification in packages.

--locked
Asserts that the exact same dependencies and versions are used as
when the existing Cargo.lock file was originally generated. Cargo
Expand Down
4 changes: 4 additions & 0 deletions src/doc/src/commands/cargo-generate-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ terminal.</li>
<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>
<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
Expand Down
4 changes: 4 additions & 0 deletions src/doc/src/commands/cargo-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ terminal.</li>
<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>
<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
Expand Down
5 changes: 5 additions & 0 deletions src/etc/man/cargo-generate-lockfile.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.RE
.sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR
.RS 4
Asserts that the exact same dependencies and versions are used as when the
Expand Down
5 changes: 5 additions & 0 deletions src/etc/man/cargo-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.RE
.sp
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.RE
.sp
\fB\-\-locked\fR
.RS 4
Asserts that the exact same dependencies and versions are used as when the
Expand Down
16 changes: 9 additions & 7 deletions tests/testsuite/cargo_generate_lockfile/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.
16 changes: 9 additions & 7 deletions tests/testsuite/cargo_update/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.
38 changes: 24 additions & 14 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,23 @@ fn generate_lockfile_msrv_resolve() {
.file("src/main.rs", "fn main(){}")
.build();

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

0 comments on commit c7d89c6

Please sign in to comment.