Skip to content

Commit

Permalink
Run Untry over the entire source tree
Browse files Browse the repository at this point in the history
  • Loading branch information
ogham committed Mar 26, 2017
1 parent c66a947 commit 3bce55f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 deletions.
20 changes: 10 additions & 10 deletions src/exa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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)?,
}
};

Expand All @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/fs/feature/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/options/dir_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
6 changes: 3 additions & 3 deletions src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
})
}

Expand Down Expand Up @@ -265,7 +265,7 @@ impl IgnorePatterns {
};

Ok(IgnorePatterns {
patterns: try!(patterns),
patterns: patterns?,
})
}

Expand Down
8 changes: 4 additions & 4 deletions src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -138,9 +138,9 @@ impl Options {
/// Determines the complete set of options based on the given command-line
/// arguments, after they’ve 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,
Expand Down
16 changes: 8 additions & 8 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand All @@ -178,7 +178,7 @@ impl View {
}
}

try!(long_options_scan());
long_options_scan()?;

other_options_scan()
}
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/output/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/output/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/output/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 3bce55f

Please sign in to comment.