From e6387854aab449557b17e0ecabf5ffb172404358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Fri, 2 Aug 2024 11:01:46 +0100 Subject: [PATCH] change dir --- devenv/src/cli.rs | 9 +++++++++ devenv/src/devenv.rs | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/devenv/src/cli.rs b/devenv/src/cli.rs index 35a541eb8..adec4beab 100644 --- a/devenv/src/cli.rs +++ b/devenv/src/cli.rs @@ -23,6 +23,14 @@ pub struct GlobalOptions { #[arg(short, long, global = true, help = "Enable debug log level.")] pub verbose: bool, + #[arg( + short = 'C', + long, + global = true, + help = "Change directory before running the command." + )] + pub change_dir: Option, + #[arg(short = 'j', long, global = true, help = "Maximum number of Nix builds at any time.", default_value_t = max_jobs())] @@ -96,6 +104,7 @@ impl Default for GlobalOptions { fn default() -> Self { Self { verbose: false, + change_dir: None, max_jobs: max_jobs(), cores: 2, system: default_system(), diff --git a/devenv/src/devenv.rs b/devenv/src/devenv.rs index 12a0da387..785228d5a 100644 --- a/devenv/src/devenv.rs +++ b/devenv/src/devenv.rs @@ -62,6 +62,13 @@ pub struct Devenv { impl Devenv { pub fn new(options: DevenvOptions) -> Self { + let global_options = options.global_options.unwrap_or_default(); + + if let Some(dir) = &global_options.change_dir { + println!("Changing directory to {}", dir.display()); + std::env::set_current_dir(&dir).expect("Failed to change directory"); + } + let xdg_dirs = xdg::BaseDirectories::with_prefix("devenv").unwrap(); let devenv_home = xdg_dirs.get_data_home(); let devenv_home_gc = devenv_home.join("gc"); @@ -89,8 +96,6 @@ impl Devenv { Path::new(&devenv_tmp).join(format!("devenv-{}", &devenv_state_hash[..7])); let cachix_trusted_keys = devenv_home.join("cachix_trusted_keys.json"); - let global_options = options.global_options.unwrap_or_default(); - let level = if global_options.verbose { log::Level::Debug } else {