Skip to content

Commit

Permalink
Auto merge of #11960 - ehuss:chdir-unstable, r=weihanglo
Browse files Browse the repository at this point in the history
Change -C to be unstable

Due to #11957, we have decided to change `-C` to be unstable to give us some more time to decide on how it should behave.
  • Loading branch information
bors committed Apr 12, 2023
2 parents 7bf43f0 + 3da2b3c commit 1ce01c5
Show file tree
Hide file tree
Showing 100 changed files with 533 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@

### Added

- Added `-C` flag for changing current dir before build starts.
[#10952](https://github.com/rust-lang/cargo/pull/10952)
- Cargo now suggests `cargo fix` or `cargo clippy --fix`
when compilation warnings are auto-fixable.
[#11558](https://github.com/rust-lang/cargo/pull/11558)
Expand Down Expand Up @@ -130,6 +128,8 @@
- Emit an error message for transitive artifact dependencies with targets the
package doesn't directly interact with.
[#11643](https://github.com/rust-lang/cargo/pull/11643)
- Added `-C` flag for changing current dir before build starts.
[#10952](https://github.com/rust-lang/cargo/pull/10952)

### Documentation

Expand Down
19 changes: 18 additions & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ pub fn main(config: &mut LazyConfig) -> CliResult {
// This must be completed before config is initialized
assert_eq!(config.is_init(), false);
if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") {
// This is a temporary hack. This cannot access `Config`, so this is a bit messy.
// This does not properly parse `-Z` flags that appear after the subcommand.
// The error message is not as helpful as the standard one.
let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev");
if !nightly_features_allowed
|| (nightly_features_allowed
&& !args
.get_many("unstable-features")
.map(|mut z| z.any(|value: &String| value == "unstable-options"))
.unwrap_or(false))
{
return Err(anyhow::format_err!(
"the `-C` flag is unstable, \
pass `-Z unstable-options` on the nightly channel to enable it"
)
.into());
}
std::env::set_current_dir(&new_cwd).context("could not change to requested directory")?;
}

Expand Down Expand Up @@ -479,7 +496,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
)
.arg(
Arg::new("directory")
.help("Change to DIRECTORY before doing anything")
.help("Change to DIRECTORY before doing anything (nightly-only)")
.short('C')
.value_name("DIRECTORY")
.value_hint(clap::ValueHint::DirPath)
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-clean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-fetch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-generate-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-locate-project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-login.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-owner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-package.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-pkgid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-publish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-remove.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-rustdoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-uninstall.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ OPTIONS
option must appear before the command name, for example cargo -C
path/to/my-project build.

This option is only available on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable (see #10098
<https://github.com/rust-lang/cargo/issues/10098>).

-h, --help
Prints help information.

Expand Down
Loading

0 comments on commit 1ce01c5

Please sign in to comment.