##// END OF EJS Templates
rhg: Make Ui::new falliable, add Ui::new_infallible...
Simon Sapin -
r49582:f591b377 default
parent child Browse files
Show More
@@ -150,7 +150,7 b' fn main() {'
150 .unwrap_or_else(|error| {
150 .unwrap_or_else(|error| {
151 exit(
151 exit(
152 &None,
152 &None,
153 &Ui::new(&Config::empty()),
153 &Ui::new_infallible(&Config::empty()),
154 OnUnsupported::Abort,
154 OnUnsupported::Abort,
155 Err(CommandError::abort(format!(
155 Err(CommandError::abort(format!(
156 "abort: {}: '{}'",
156 "abort: {}: '{}'",
@@ -171,7 +171,7 b' fn main() {'
171
171
172 exit(
172 exit(
173 &initial_current_dir,
173 &initial_current_dir,
174 &Ui::new(&Config::empty()),
174 &Ui::new_infallible(&Config::empty()),
175 on_unsupported,
175 on_unsupported,
176 Err(error.into()),
176 Err(error.into()),
177 false,
177 false,
@@ -183,7 +183,7 b' fn main() {'
183 .unwrap_or_else(|error| {
183 .unwrap_or_else(|error| {
184 exit(
184 exit(
185 &initial_current_dir,
185 &initial_current_dir,
186 &Ui::new(&non_repo_config),
186 &Ui::new_infallible(&non_repo_config),
187 OnUnsupported::from_config(&non_repo_config),
187 OnUnsupported::from_config(&non_repo_config),
188 Err(error.into()),
188 Err(error.into()),
189 non_repo_config
189 non_repo_config
@@ -201,7 +201,7 b' fn main() {'
201 if SCHEME_RE.is_match(&repo_path_bytes) {
201 if SCHEME_RE.is_match(&repo_path_bytes) {
202 exit(
202 exit(
203 &initial_current_dir,
203 &initial_current_dir,
204 &Ui::new(&non_repo_config),
204 &Ui::new_infallible(&non_repo_config),
205 OnUnsupported::from_config(&non_repo_config),
205 OnUnsupported::from_config(&non_repo_config),
206 Err(CommandError::UnsupportedFeature {
206 Err(CommandError::UnsupportedFeature {
207 message: format_bytes!(
207 message: format_bytes!(
@@ -291,7 +291,7 b' fn main() {'
291 }
291 }
292 Err(error) => exit(
292 Err(error) => exit(
293 &initial_current_dir,
293 &initial_current_dir,
294 &Ui::new(&non_repo_config),
294 &Ui::new_infallible(&non_repo_config),
295 OnUnsupported::from_config(&non_repo_config),
295 OnUnsupported::from_config(&non_repo_config),
296 Err(error.into()),
296 Err(error.into()),
297 // TODO: show a warning or combine with original error if
297 // TODO: show a warning or combine with original error if
@@ -307,7 +307,17 b' fn main() {'
307 } else {
307 } else {
308 &non_repo_config
308 &non_repo_config
309 };
309 };
310 let ui = Ui::new(&config);
310 let ui = Ui::new(&config).unwrap_or_else(|error| {
311 exit(
312 &initial_current_dir,
313 &Ui::new_infallible(&config),
314 OnUnsupported::from_config(&config),
315 Err(error.into()),
316 config
317 .get_bool(b"ui", b"detailed-exit-code")
318 .unwrap_or(false),
319 )
320 });
311 let on_unsupported = OnUnsupported::from_config(config);
321 let on_unsupported = OnUnsupported::from_config(config);
312
322
313 let result = main_with_result(
323 let result = main_with_result(
@@ -1,5 +1,6 b''
1 use format_bytes::format_bytes;
1 use format_bytes::format_bytes;
2 use hg::config::Config;
2 use hg::config::Config;
3 use hg::errors::HgError;
3 use hg::utils::files::get_bytes_from_os_string;
4 use hg::utils::files::get_bytes_from_os_string;
4 use std::borrow::Cow;
5 use std::borrow::Cow;
5 use std::env;
6 use std::env;
@@ -22,7 +23,17 b' pub enum UiError {'
22
23
23 /// The commandline user interface
24 /// The commandline user interface
24 impl Ui {
25 impl Ui {
25 pub fn new(_config: &Config) -> Self {
26 pub fn new(_config: &Config) -> Result<Self, HgError> {
27 Ok(Ui {
28 stdout: std::io::stdout(),
29 stderr: std::io::stderr(),
30 })
31 }
32
33 /// Default to no color if color configuration errors.
34 ///
35 /// Useful when we’re already handling another error.
36 pub fn new_infallible(_config: &Config) -> Self {
26 Ui {
37 Ui {
27 stdout: std::io::stdout(),
38 stdout: std::io::stdout(),
28 stderr: std::io::stderr(),
39 stderr: std::io::stderr(),
General Comments 0
You need to be logged in to leave comments. Login now