|
1 |
| -use anyhow::anyhow; |
| 1 | +use anyhow::{anyhow, Context as _}; |
2 | 2 | use cargo::core::shell::Shell;
|
3 | 3 | use cargo::core::{features, CliUnstable};
|
4 | 4 | use cargo::{self, drop_print, drop_println, CliResult, Config};
|
@@ -27,6 +27,12 @@ lazy_static::lazy_static! {
|
27 | 27 | pub fn main(config: &mut LazyConfig) -> CliResult {
|
28 | 28 | let args = cli().try_get_matches()?;
|
29 | 29 |
|
| 30 | + // Update the process-level notion of cwd |
| 31 | + if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") { |
| 32 | + std::env::set_current_dir(&new_cwd) |
| 33 | + .with_context(|| "could not change to requested directory")?; |
| 34 | + } |
| 35 | + |
30 | 36 | // CAUTION: Be careful with using `config` until it is configured below.
|
31 | 37 | // In general, try to avoid loading config values unless necessary (like
|
32 | 38 | // the [alias] table).
|
@@ -467,6 +473,13 @@ See 'cargo help <command>' for more information on a specific command.\n",
|
467 | 473 | .value_name("WHEN")
|
468 | 474 | .global(true),
|
469 | 475 | )
|
| 476 | + .arg( |
| 477 | + opt("directory", "Change to DIRECTORY before doing anything") |
| 478 | + .short('C') |
| 479 | + .value_name("DIRECTORY") |
| 480 | + .value_hint(clap::ValueHint::DirPath) |
| 481 | + .value_parser(clap::builder::ValueParser::path_buf()), |
| 482 | + ) |
470 | 483 | .arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true))
|
471 | 484 | .arg(flag("locked", "Require Cargo.lock is up to date").global(true))
|
472 | 485 | .arg(flag("offline", "Run without accessing the network").global(true))
|
|
0 commit comments