mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 11:47:01 +05:30
Simplify error handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
9da03c9207
commit
598c81e249
1 changed files with 4 additions and 17 deletions
21
src/main.rs
21
src/main.rs
|
@ -2,12 +2,12 @@ use git2::Repository;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> anyhow::Result<()> {
|
||||||
let dir = match std::env::args().nth(1) {
|
let dir = match std::env::args().nth(1) {
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => {
|
None => {
|
||||||
println!("Usage:\n gitice <dir>\n");
|
println!("Usage:\n gitice <dir>\n");
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut items: Vec<String> = Vec::new();
|
let mut items: Vec<String> = Vec::new();
|
||||||
|
@ -16,27 +16,14 @@ fn main() {
|
||||||
let path = format!("{}/.git", entry.path().display());
|
let path = format!("{}/.git", entry.path().display());
|
||||||
let git_dir = Path::new(&path);
|
let git_dir = Path::new(&path);
|
||||||
if git_dir.exists() {
|
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!(
|
items.push(format!(
|
||||||
"{} = {}",
|
"{} = {}",
|
||||||
entry.path().to_string_lossy().to_string(),
|
entry.path().to_string_lossy().to_string(),
|
||||||
head.name().unwrap()
|
Repository::open(git_dir)?.head()?.name().unwrap_or("None")
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
println!("{:#x?}", items);
|
println!("{:#x?}", items);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue