mirror of
https://github.com/msfjarvis/gitice.git
synced 2024-06-03 03:58:56 +05:30
Simplify error handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
9da03c9207
commit
598c81e249
21
src/main.rs
21
src/main.rs
|
@ -2,12 +2,12 @@ use git2::Repository;
|
|||
use std::path::Path;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
fn main() {
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let dir = match std::env::args().nth(1) {
|
||||
Some(d) => d,
|
||||
None => {
|
||||
println!("Usage:\n gitice <dir>\n");
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
let mut items: Vec<String> = Vec::new();
|
||||
|
@ -16,27 +16,14 @@ fn main() {
|
|||
let path = format!("{}/.git", entry.path().display());
|
||||
let git_dir = Path::new(&path);
|
||||
if git_dir.exists() {
|
||||
let repo = match Repository::open(git_dir) {
|
||||
Ok(repo) => repo,
|
||||
Err(e) => {
|
||||
println!("Failed to open repository: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let head = match repo.head() {
|
||||
Ok(head) => head,
|
||||
Err(e) => {
|
||||
println!("Failed getting repository head: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
items.push(format!(
|
||||
"{} = {}",
|
||||
entry.path().to_string_lossy().to_string(),
|
||||
head.name().unwrap()
|
||||
Repository::open(git_dir)?.head()?.name().unwrap_or("None")
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
println!("{:#x?}", items);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user