mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 11:33:10 +00:00
Add context for errors when browsing featured cheatsheets.
This commit is contained in:
parent
70ec05ba5e
commit
1d33211c45
2 changed files with 13 additions and 6 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -16,6 +16,11 @@ dependencies = [
|
||||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayref"
|
name = "arrayref"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
|
@ -247,6 +252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
name = "navi"
|
name = "navi"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -657,6 +663,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
"checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada"
|
||||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||||
|
"checksum anyhow 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "013a6e0a2cbe3d20f9c60b65458f7a7f7a5e636c5d0f45a5a6aee5d4b1f01785"
|
||||||
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
|
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
|
||||||
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||||
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::filesystem;
|
||||||
use crate::fzf;
|
use crate::fzf;
|
||||||
use crate::git;
|
use crate::git;
|
||||||
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
|
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
|
||||||
|
use anyhow::Context;
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -14,13 +15,12 @@ pub fn browse() -> Result<(), Box<dyn Error>> {
|
||||||
filesystem::remove_dir(&repo_path_str);
|
filesystem::remove_dir(&repo_path_str);
|
||||||
filesystem::create_dir(&repo_path_str);
|
filesystem::create_dir(&repo_path_str);
|
||||||
|
|
||||||
match Repository::clone("https://github.com/denisidoro/cheats", &repo_path_str) {
|
let repo_url = "https://github.com/denisidoro/cheats";
|
||||||
Ok(r) => r,
|
Repository::clone(repo_url, &repo_path_str)
|
||||||
Err(e) => panic!("failed to clone: {}", e),
|
.with_context(|| format!("Failed to clone {}.", repo_url))?;
|
||||||
};
|
|
||||||
|
|
||||||
let repos = fs::read_to_string(format!("{}/featured_repos.txt", &repo_path_str))
|
let repos = fs::read_to_string(format!("{}/featured_repos.txt", &repo_path_str))
|
||||||
.expect("Unable to fetch featured repos");
|
.context("Unable to fetch featured repos.")?;
|
||||||
|
|
||||||
let opts = FzfOpts {
|
let opts = FzfOpts {
|
||||||
column: Some(1),
|
column: Some(1),
|
||||||
|
@ -30,7 +30,7 @@ pub fn browse() -> Result<(), Box<dyn Error>> {
|
||||||
let (repo, _) = fzf::call(opts, |stdin| {
|
let (repo, _) = fzf::call(opts, |stdin| {
|
||||||
stdin
|
stdin
|
||||||
.write_all(repos.as_bytes())
|
.write_all(repos.as_bytes())
|
||||||
.expect("Unable to prompt featured repos");
|
.expect("Unable to prompt featured repos.");
|
||||||
None
|
None
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue