check config file before prompts on x setup · rust-lang/rust@3d6417f (original) (raw)

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -122,6 +122,17 @@ impl Step for Profile {
122 122 return;
123 123 }
124 124
125 +let path = &run.builder.config.config.clone().unwrap_or(PathBuf::from("config.toml"));
126 +if path.exists() {
127 +eprintln!();
128 +eprintln!(
129 +"error: you asked for a new config file, but one already exists at `{}`",
130 + t!(path.canonicalize()).display()
131 +);
132 +
133 +crate::exit!(1);
134 +}
135 +
125 136 // for Profile, `run.paths` will have 1 and only 1 element
126 137 // this is because we only accept at most 1 path from user input.
127 138 // If user calls `x.py setup` without arguments, the interactive TUI
@@ -204,19 +215,6 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
204 215 if profile == Profile::None {
205 216 return;
206 217 }
207 -if path.exists() {
208 -eprintln!();
209 -eprintln!(
210 -"error: you asked `x.py` to setup a new config file, but one already exists at `{}`",
211 - path.display()
212 -);
213 -eprintln!("help: try adding `profile = \"{}\"` at the top of {}", profile, path.display());
214 -eprintln!(
215 -"note: this will use the configuration in {}",
216 - profile.include_path(&config.src).display()
217 -);
218 -crate::exit!(1);
219 -}
220 218
221 219 let latest_change_id = CONFIG_CHANGE_HISTORY.last().unwrap();
222 220 let settings = format!(