@@ -60,9 +60,10 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
60
60
} )
61
61
}
62
62
63
- pub fn run ( & mut self ) -> IOResult < ( ) > {
63
+ pub fn run ( & mut self ) -> IOResult < i32 > {
64
64
let mut files = Vec :: new ( ) ;
65
65
let mut dirs = Vec :: new ( ) ;
66
+ let mut exit_status = 0 ;
66
67
67
68
// List the current directory by default, like ls.
68
69
if self . args . is_empty ( ) {
@@ -72,6 +73,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
72
73
for file_name in self . args . iter ( ) {
73
74
match File :: from_path ( Path :: new ( & file_name) , None ) {
74
75
Err ( e) => {
76
+ exit_status = 2 ;
75
77
writeln ! ( stderr( ) , "{}: {}" , file_name, e) ?;
76
78
} ,
77
79
Ok ( f) => {
@@ -98,10 +100,10 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
98
100
self . options . filter . filter_argument_files ( & mut files) ;
99
101
self . print_files ( None , files) ?;
100
102
101
- self . print_dirs ( dirs, no_files, is_only_dir)
103
+ self . print_dirs ( dirs, no_files, is_only_dir, exit_status )
102
104
}
103
105
104
- fn print_dirs ( & mut self , dir_files : Vec < Dir > , mut first : bool , is_only_dir : bool ) -> IOResult < ( ) > {
106
+ fn print_dirs ( & mut self , dir_files : Vec < Dir > , mut first : bool , is_only_dir : bool , exit_status : i32 ) -> IOResult < i32 > {
105
107
for dir in dir_files {
106
108
107
109
// Put a gap between directories, or between the list of files and
@@ -141,15 +143,18 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
141
143
}
142
144
143
145
self . print_files ( Some ( & dir) , children) ?;
144
- self . print_dirs ( child_dirs, false , false ) ?;
146
+ match self . print_dirs ( child_dirs, false , false , exit_status) {
147
+ Ok ( _) => ( ) ,
148
+ Err ( e) => return Err ( e) ,
149
+ }
145
150
continue ;
146
151
}
147
152
}
148
153
149
154
self . print_files ( Some ( & dir) , children) ?;
150
155
}
151
156
152
- Ok ( ( ) )
157
+ Ok ( exit_status )
153
158
}
154
159
155
160
/// Prints the list of files using whichever view is selected.
0 commit comments