Skip to content

Commit

Permalink
check config file before prompts on x setup
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Nov 9, 2023
1 parent d8dbf7c commit 3d6417f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ impl Step for Profile {
return;
}

let path = &run.builder.config.config.clone().unwrap_or(PathBuf::from("config.toml"));
if path.exists() {
eprintln!();
eprintln!(
"error: you asked for a new config file, but one already exists at `{}`",
t!(path.canonicalize()).display()
);

crate::exit!(1);
}

// for Profile, `run.paths` will have 1 and only 1 element
// this is because we only accept at most 1 path from user input.
// If user calls `x.py setup` without arguments, the interactive TUI
Expand Down Expand Up @@ -204,19 +215,6 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
if profile == Profile::None {
return;
}
if path.exists() {
eprintln!();
eprintln!(
"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
path.display()
);
eprintln!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
eprintln!(
"note: this will use the configuration in {}",
profile.include_path(&config.src).display()
);
crate::exit!(1);
}

let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap();
let settings = format!(
Expand Down

0 comments on commit 3d6417f

Please sign in to comment.