Run Untry over the entire source tree

This commit is contained in:
Benjamin Sago 2017-03-26 17:35:50 +01:00
parent c66a947a74
commit 3bce55f569
10 changed files with 33 additions and 33 deletions

View File

@ -72,13 +72,13 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
for file_name in self.args.iter() {
match File::from_path(Path::new(&file_name), None) {
Err(e) => {
try!(writeln!(stderr(), "{}: {}", file_name, e));
writeln!(stderr(), "{}: {}", file_name, e)?;
},
Ok(f) => {
if f.is_directory() && !self.options.dir_action.treat_dirs_as_files() {
match f.to_dir(self.options.should_scan_for_git()) {
Ok(d) => dirs.push(d),
Err(e) => try!(writeln!(stderr(), "{}: {}", file_name, e)),
Err(e) => writeln!(stderr(), "{}: {}", file_name, e)?,
}
}
else {
@ -96,7 +96,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
let is_only_dir = dirs.len() == 1 && no_files;
self.options.filter.filter_argument_files(&mut files);
try!(self.print_files(None, files));
self.print_files(None, files)?;
self.print_dirs(dirs, no_files, is_only_dir)
}
@ -110,18 +110,18 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
first = false;
}
else {
try!(write!(self.writer, "\n"));
write!(self.writer, "\n")?;
}
if !is_only_dir {
try!(writeln!(self.writer, "{}:", dir.path.display()));
writeln!(self.writer, "{}:", dir.path.display())?;
}
let mut children = Vec::new();
for file in dir.files() {
match file {
Ok(file) => children.push(file),
Err((path, e)) => try!(writeln!(stderr(), "[{}: {}]", path.display(), e)),
Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?,
}
};
@ -136,17 +136,17 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
for child_dir in children.iter().filter(|f| f.is_directory()) {
match child_dir.to_dir(false) {
Ok(d) => child_dirs.push(d),
Err(e) => try!(writeln!(stderr(), "{}: {}", child_dir.path.display(), e)),
Err(e) => writeln!(stderr(), "{}: {}", child_dir.path.display(), e)?,
}
}
try!(self.print_files(Some(&dir), children));
try!(self.print_dirs(child_dirs, false, false));
self.print_files(Some(&dir), children)?;
self.print_dirs(child_dirs, false, false)?;
continue;
}
}
try!(self.print_files(Some(&dir), children));
self.print_files(Some(&dir), children)?;
}
Ok(())

View File

@ -33,7 +33,7 @@ impl Dir {
/// isn't actually a directory, or if there's an IO error that occurs
/// while scanning.
pub fn read_dir(path: &Path, git: bool) -> IOResult<Dir> {
let reader = try!(fs::read_dir(path));
let reader = fs::read_dir(path)?;
let contents = try!(reader.map(|e| e.map(|e| e.path())).collect());
Ok(Dir {

View File

@ -15,13 +15,13 @@ impl Git {
/// Discover a Git repository on or above this directory, scanning it for
/// the files' statuses if one is found.
pub fn scan(path: &Path) -> Result<Git, git2::Error> {
let repo = try!(git2::Repository::discover(path));
let repo = git2::Repository::discover(path)?;
let workdir = match repo.workdir() {
Some(w) => w,
None => return Ok(Git { statuses: vec![] }), // bare repo
};
let statuses = try!(repo.statuses(None)).iter()
let statuses = repo.statuses(None)?.iter()
.map(|e| (workdir.join(Path::new(e.path().unwrap())), e.status()))
.collect();

View File

@ -36,8 +36,8 @@ impl DirAction {
(true, true, _ ) => Err(Misfire::Conflict("recurse", "list-dirs")),
(_, true, true ) => Err(Misfire::Conflict("tree", "list-dirs")),
(_ , _, true ) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, true)))),
(true, false, false) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, false)))),
(_ , _, true ) => Ok(DirAction::Recurse(RecurseOptions::deduce(matches, true)?)),
(true, false, false) => Ok(DirAction::Recurse(RecurseOptions::deduce(matches, false)?)),
(false, true, _ ) => Ok(DirAction::AsFile),
(false, false, _ ) => Ok(DirAction::List),
}

View File

@ -75,9 +75,9 @@ impl FileFilter {
Ok(FileFilter {
list_dirs_first: matches.opt_present("group-directories-first"),
reverse: matches.opt_present("reverse"),
sort_field: try!(SortField::deduce(matches)),
sort_field: SortField::deduce(matches)?,
show_invisibles: matches.opt_present("all"),
ignore_patterns: try!(IgnorePatterns::deduce(matches)),
ignore_patterns: IgnorePatterns::deduce(matches)?,
})
}
@ -265,7 +265,7 @@ impl IgnorePatterns {
};
Ok(IgnorePatterns {
patterns: try!(patterns),
patterns: patterns?,
})
}

View File

@ -120,7 +120,7 @@ impl Options {
return Err(Misfire::Version);
}
let options = try!(Options::deduce(&matches));
let options = Options::deduce(&matches)?;
Ok((options, matches.free))
}
@ -138,9 +138,9 @@ impl Options {
/// Determines the complete set of options based on the given command-line
/// arguments, after theyve been parsed.
fn deduce(matches: &getopts::Matches) -> Result<Options, Misfire> {
let dir_action = try!(DirAction::deduce(&matches));
let filter = try!(FileFilter::deduce(&matches));
let view = try!(View::deduce(&matches, filter.clone(), dir_action));
let dir_action = DirAction::deduce(&matches)?;
let filter = FileFilter::deduce(&matches)?;
let view = View::deduce(&matches, filter.clone(), dir_action)?;
Ok(Options {
dir_action: dir_action,

View File

@ -37,7 +37,7 @@ impl View {
Err(Useless("oneline", true, "long"))
}
else {
let term_colours = try!(TerminalColours::deduce(matches));
let term_colours = TerminalColours::deduce(matches)?;
let colours = match term_colours {
TerminalColours::Always => Colours::colourful(colour_scale()),
TerminalColours::Never => Colours::plain(),
@ -52,7 +52,7 @@ impl View {
};
let details = Details {
columns: Some(try!(Columns::deduce(matches))),
columns: Some(Columns::deduce(matches)?),
header: matches.opt_present("header"),
recurse: dir_action.recurse_options(),
filter: filter.clone(),
@ -86,8 +86,8 @@ impl View {
};
let other_options_scan = || {
let term_colours = try!(TerminalColours::deduce(matches));
let term_width = try!(TerminalWidth::deduce());
let term_colours = TerminalColours::deduce(matches)?;
let term_width = TerminalWidth::deduce()?;
if let Some(&width) = term_width.as_ref() {
let colours = match term_colours {
@ -164,7 +164,7 @@ impl View {
};
if matches.opt_present("long") {
let long_options = try!(long());
let long_options = long()?;
if matches.opt_present("grid") {
match other_options_scan() {
@ -178,7 +178,7 @@ impl View {
}
}
try!(long_options_scan());
long_options_scan()?;
other_options_scan()
}
@ -232,8 +232,8 @@ impl TerminalWidth {
impl Columns {
fn deduce(matches: &getopts::Matches) -> Result<Columns, Misfire> {
Ok(Columns {
size_format: try!(SizeFormat::deduce(matches)),
time_types: try!(TimeTypes::deduce(matches)),
size_format: SizeFormat::deduce(matches)?,
time_types: TimeTypes::deduce(matches)?,
inode: matches.opt_present("inode"),
links: matches.opt_present("links"),
blocks: matches.opt_present("blocks"),

View File

@ -218,7 +218,7 @@ impl Details {
// Then add files to the table and print it out.
self.add_files_to_table(&mut table, files, 0);
for cell in table.print_table() {
try!(writeln!(w, "{}", cell.strings()));
writeln!(w, "{}", cell.strings())?;
}
Ok(())

View File

@ -48,7 +48,7 @@ impl Grid {
else {
// File names too long for a grid - drop down to just listing them!
for file in files.iter() {
try!(writeln!(w, "{}", filename(file, &self.colours, false).strings()));
writeln!(w, "{}", filename(file, &self.colours, false).strings())?;
}
Ok(())
}

View File

@ -17,7 +17,7 @@ pub struct Lines {
impl Lines {
pub fn view<W: Write>(&self, files: Vec<File>, w: &mut W) -> IOResult<()> {
for file in files {
try!(writeln!(w, "{}", ANSIStrings(&filename(&file, &self.colours, true))));
writeln!(w, "{}", ANSIStrings(&filename(&file, &self.colours, true)))?;
}
Ok(())
}