Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dir #1359

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

#[arg(short = 'j', long,
global = true, help = "Maximum number of Nix builds at any time.",
default_value_t = max_jobs())]
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions devenv/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down
Loading