mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-02-02 10:38:24 +00:00
Merge pull request #146 from spk/fix-exit-status
Exit with a non-zero status on error
This commit is contained in:
commit
f1be6b89d5
@ -10,7 +10,10 @@ fn main() {
|
|||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
|
||||||
match Exa::new(&args, &mut stdout) {
|
match Exa::new(&args, &mut stdout) {
|
||||||
Ok(mut exa) => if let Err(e) = exa.run() {
|
Ok(mut exa) => {
|
||||||
|
match exa.run() {
|
||||||
|
Ok(exit_status) => exit(exit_status),
|
||||||
|
Err(e) => {
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
ErrorKind::BrokenPipe => exit(0),
|
ErrorKind::BrokenPipe => exit(0),
|
||||||
_ => {
|
_ => {
|
||||||
@ -18,6 +21,8 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
writeln!(stderr(), "{}", e).unwrap();
|
writeln!(stderr(), "{}", e).unwrap();
|
||||||
|
15
src/exa.rs
15
src/exa.rs
@ -60,9 +60,10 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) -> IOResult<()> {
|
pub fn run(&mut self) -> IOResult<i32> {
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
let mut dirs = Vec::new();
|
let mut dirs = Vec::new();
|
||||||
|
let mut exit_status = 0;
|
||||||
|
|
||||||
// List the current directory by default, like ls.
|
// List the current directory by default, like ls.
|
||||||
if self.args.is_empty() {
|
if self.args.is_empty() {
|
||||||
@ -72,6 +73,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
for file_name in self.args.iter() {
|
for file_name in self.args.iter() {
|
||||||
match File::from_path(Path::new(&file_name), None) {
|
match File::from_path(Path::new(&file_name), None) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
exit_status = 2;
|
||||||
writeln!(stderr(), "{}: {}", file_name, e)?;
|
writeln!(stderr(), "{}: {}", file_name, e)?;
|
||||||
},
|
},
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
@ -98,10 +100,10 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
self.options.filter.filter_argument_files(&mut files);
|
self.options.filter.filter_argument_files(&mut files);
|
||||||
self.print_files(None, files)?;
|
self.print_files(None, files)?;
|
||||||
|
|
||||||
self.print_dirs(dirs, no_files, is_only_dir)
|
self.print_dirs(dirs, no_files, is_only_dir, exit_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool) -> IOResult<()> {
|
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool, exit_status: i32) -> IOResult<i32> {
|
||||||
for dir in dir_files {
|
for dir in dir_files {
|
||||||
|
|
||||||
// Put a gap between directories, or between the list of files and
|
// Put a gap between directories, or between the list of files and
|
||||||
@ -141,7 +143,10 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.print_files(Some(&dir), children)?;
|
self.print_files(Some(&dir), children)?;
|
||||||
self.print_dirs(child_dirs, false, false)?;
|
match self.print_dirs(child_dirs, false, false, exit_status) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => return Err(e),
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +154,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
self.print_files(Some(&dir), children)?;
|
self.print_files(Some(&dir), children)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(exit_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints the list of files using whichever view is selected.
|
/// Prints the list of files using whichever view is selected.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user