Show More
@@ -301,6 +301,24 b' fn rhg_main(argv: Vec<OsString>) -> ! {' | |||||
301 | } |
|
301 | } | |
302 | }; |
|
302 | }; | |
303 |
|
303 | |||
|
304 | let exit = | |||
|
305 | |ui: &Ui, config: &Config, result: Result<(), CommandError>| -> ! { | |||
|
306 | exit( | |||
|
307 | &argv, | |||
|
308 | &initial_current_dir, | |||
|
309 | ui, | |||
|
310 | OnUnsupported::from_config(config), | |||
|
311 | result, | |||
|
312 | // TODO: show a warning or combine with original error if | |||
|
313 | // `get_bool` returns an error | |||
|
314 | non_repo_config | |||
|
315 | .get_bool(b"ui", b"detailed-exit-code") | |||
|
316 | .unwrap_or(false), | |||
|
317 | ) | |||
|
318 | }; | |||
|
319 | let early_exit = |config: &Config, error: CommandError| -> ! { | |||
|
320 | exit(&Ui::new_infallible(config), &config, Err(error)) | |||
|
321 | }; | |||
304 | let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned()) |
|
322 | let repo_result = match Repo::find(&non_repo_config, repo_path.to_owned()) | |
305 | { |
|
323 | { | |
306 | Ok(repo) => Ok(repo), |
|
324 | Ok(repo) => Ok(repo), | |
@@ -308,18 +326,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {' | |||||
308 | // Not finding a repo is not fatal yet, if `-R` was not given |
|
326 | // Not finding a repo is not fatal yet, if `-R` was not given | |
309 | Err(NoRepoInCwdError { cwd: at }) |
|
327 | Err(NoRepoInCwdError { cwd: at }) | |
310 | } |
|
328 | } | |
311 | Err(error) => exit( |
|
329 | Err(error) => early_exit(&non_repo_config, error.into()), | |
312 | &argv, |
|
|||
313 | &initial_current_dir, |
|
|||
314 | &Ui::new_infallible(&non_repo_config), |
|
|||
315 | OnUnsupported::from_config(&non_repo_config), |
|
|||
316 | Err(error.into()), |
|
|||
317 | // TODO: show a warning or combine with original error if |
|
|||
318 | // `get_bool` returns an error |
|
|||
319 | non_repo_config |
|
|||
320 | .get_bool(b"ui", b"detailed-exit-code") |
|
|||
321 | .unwrap_or(false), |
|
|||
322 | ), |
|
|||
323 | }; |
|
330 | }; | |
324 |
|
331 | |||
325 | let config = if let Ok(repo) = &repo_result { |
|
332 | let config = if let Ok(repo) = &repo_result { | |
@@ -334,36 +341,13 b' fn rhg_main(argv: Vec<OsString>) -> ! {' | |||||
334 | && config_cow |
|
341 | && config_cow | |
335 | .as_ref() |
|
342 | .as_ref() | |
336 | .get_bool(b"ui", b"tweakdefaults") |
|
343 | .get_bool(b"ui", b"tweakdefaults") | |
337 |
.unwrap_or_else(|error| |
|
344 | .unwrap_or_else(|error| early_exit(&config, error.into())) | |
338 | exit( |
|
|||
339 | &argv, |
|
|||
340 | &initial_current_dir, |
|
|||
341 | &Ui::new_infallible(&config), |
|
|||
342 | OnUnsupported::from_config(&config), |
|
|||
343 | Err(error.into()), |
|
|||
344 | config |
|
|||
345 | .get_bool(b"ui", b"detailed-exit-code") |
|
|||
346 | .unwrap_or(false), |
|
|||
347 | ) |
|
|||
348 | }) |
|
|||
349 | { |
|
345 | { | |
350 | config_cow.to_mut().tweakdefaults() |
|
346 | config_cow.to_mut().tweakdefaults() | |
351 | }; |
|
347 | }; | |
352 | let config = config_cow.as_ref(); |
|
348 | let config = config_cow.as_ref(); | |
353 |
let ui = Ui::new(&config) |
|
349 | let ui = Ui::new(&config) | |
354 | exit( |
|
350 | .unwrap_or_else(|error| early_exit(&config, error.into())); | |
355 | &argv, |
|
|||
356 | &initial_current_dir, |
|
|||
357 | &Ui::new_infallible(&config), |
|
|||
358 | OnUnsupported::from_config(&config), |
|
|||
359 | Err(error.into()), |
|
|||
360 | config |
|
|||
361 | .get_bool(b"ui", b"detailed-exit-code") |
|
|||
362 | .unwrap_or(false), |
|
|||
363 | ) |
|
|||
364 | }); |
|
|||
365 | let on_unsupported = OnUnsupported::from_config(config); |
|
|||
366 |
|
||||
367 | let result = main_with_result( |
|
351 | let result = main_with_result( | |
368 | argv.iter().map(|s| s.to_owned()).collect(), |
|
352 | argv.iter().map(|s| s.to_owned()).collect(), | |
369 | &process_start_time, |
|
353 | &process_start_time, | |
@@ -371,18 +355,7 b' fn rhg_main(argv: Vec<OsString>) -> ! {' | |||||
371 | repo_result.as_ref(), |
|
355 | repo_result.as_ref(), | |
372 | config, |
|
356 | config, | |
373 | ); |
|
357 | ); | |
374 | exit( |
|
358 | exit(&ui, &config, result) | |
375 | &argv, |
|
|||
376 | &initial_current_dir, |
|
|||
377 | &ui, |
|
|||
378 | on_unsupported, |
|
|||
379 | result, |
|
|||
380 | // TODO: show a warning or combine with original error if `get_bool` |
|
|||
381 | // returns an error |
|
|||
382 | config |
|
|||
383 | .get_bool(b"ui", b"detailed-exit-code") |
|
|||
384 | .unwrap_or(false), |
|
|||
385 | ) |
|
|||
386 | } |
|
359 | } | |
387 |
|
360 | |||
388 | fn main() -> ! { |
|
361 | fn main() -> ! { |
General Comments 0
You need to be logged in to leave comments.
Login now