on master help sign in
inline a closure which is called only once
dc0acbbrhysd
src/controller.rs+5−9
@@ -89,15 +89,7 @@ impl<'b> Controller<'b> {
89
89
90 let writer = output_type.handle()?;
90 let writer = output_type.handle()?;
91 let mut no_errors: bool = true;
91 let mut no_errors: bool = true;
92−
93 let stderr = io::stderr();
92 let stderr = io::stderr();
94− let print_error = |error: &Error, write: &mut dyn Write| {
95− if attached_to_pager {
96− handle_error(error, write);
97− } else {
98− handle_error(error, &mut stderr.lock());
99− }
100− };
101
93
102 for (index, input) in inputs.into_iter().enumerate() {
94 for (index, input) in inputs.into_iter().enumerate() {
103 let identifier = stdout_identifier.as_ref();
95 let identifier = stdout_identifier.as_ref();
@@ -109,7 +101,11 @@ impl<'b> Controller<'b> {
109 self.print_input(input, writer, DummyStdin, identifier, is_first)
101 self.print_input(input, writer, DummyStdin, identifier, is_first)
110 };
102 };
111 if let Err(error) = result {
103 if let Err(error) = result {
104+ if attached_to_pager {
112− print_error(&error, writer);
105+ handle_error(&error, writer);
106+ } else {
107+ handle_error(&error, &mut stderr.lock());
108+ }
113 no_errors = false;
109 no_errors = false;
114 }
110 }
115 }
111 }