Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Oct 11, 2020
1 parent 444f3b2 commit f9e86a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ error_chain! {
}
}

pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
writeln!(output, "{}: {}", "[onefetch error]".red(), error).ok();
pub fn default_error_handler(e: &Error, output: &mut dyn Write) {
writeln!(output, "{}: {}", "[onefetch error]".red(), e).ok();

for e in e.iter().skip(1) {
writeln!(output, "caused by: {}", e).ok();
}
}
23 changes: 17 additions & 6 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,11 @@ impl std::fmt::Display for Info {
impl Info {
#[tokio::main]
pub async fn new(config: Options) -> Result<Info> {
let repo = Repository::discover(&config.path).chain_err(||"Could not find a valid git repo on the current path")?;
let workdir = repo.workdir().chain_err(||"Unable to run onefetch on bare git repo")?;
let repo = Repository::discover(&config.path)
.chain_err(|| "Could not find a valid git repo on the current path")?;
let workdir = repo
.workdir()
.chain_err(|| "Unable to run onefetch on bare git repo")?;
let workdir_str = workdir.to_str().unwrap();
let (languages_stats, number_of_lines) =
Language::get_language_stats(workdir_str, &config.excluded)?;
Expand Down Expand Up @@ -485,7 +488,9 @@ impl Info {
}

async fn get_repo_name_and_url(repo: &Repository) -> (String, String) {
let config = repo.config().chain_err(|| "Could not retrieve git configuration data");
let config = repo
.config()
.chain_err(|| "Could not retrieve git configuration data");
let mut remote_url = String::new();
let mut repository_name = String::new();

Expand Down Expand Up @@ -518,9 +523,15 @@ impl Info {
}

async fn get_current_commit_info(repo: &Repository) -> Result<CommitInfo> {
let head = repo.head().chain_err(|| "Error while retrieving reference information")?;
let head_oid = head.target().ok_or("Error while retrieving reference information")?;
let refs = repo.references().chain_err(|| "Error while retrieving reference information")?;
let head = repo
.head()
.chain_err(|| "Error while retrieving reference information")?;
let head_oid = head
.target()
.ok_or("Error while retrieving reference information")?;
let refs = repo
.references()
.chain_err(|| "Error while retrieving reference information")?;
let refs_info = refs
.filter_map(|reference| match reference {
Ok(reference) => match (reference.target(), reference.shorthand()) {
Expand Down
4 changes: 2 additions & 2 deletions src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl Language {
ignored_directories: &[String],
) -> Result<(Vec<(Language, f64)>, usize)> {
let tokei_langs = project_languages(&dir, ignored_directories);
let languages_stat =
Language::get_languages_stat(&tokei_langs).ok_or("ErrorKind::SourceCodeNotFound()")?;
let languages_stat = Language::get_languages_stat(&tokei_langs)
.ok_or("Could not find any source code in this directory")?;
let mut stat_vec: Vec<(_, _)> = languages_stat.into_iter().collect();
stat_vec.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap().reverse());
let loc = get_total_loc(&tokei_langs);
Expand Down

0 comments on commit f9e86a0

Please sign in to comment.