summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2020-03-24 11:42:18 -0300
committerGitHub <noreply@github.com>2020-03-24 11:42:18 -0300
commit65154663db8b169df9ea7a05a201d5e701e6778c (patch)
tree02c6cfa81201173e178f77aae032bdbf881fb46f
parent6ed7cd12b5e141e6347d3e8f4d9077b7b260cfda (diff)
Fix path error on initial run (#313)v2.4.1
Fixes #312 This isn't idiomatic but it'll do for the time being
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rwxr-xr-xscripts/docker8
-rw-r--r--src/flows/repo.rs2
-rw-r--r--src/parser.rs34
5 files changed, 29 insertions, 19 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 383e5cc..4bac0b7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -250,7 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "navi"
-version = "2.4.0"
+version = "2.4.1"
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)",
diff --git a/Cargo.toml b/Cargo.toml
index 8f94a1c..2b558a4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "navi"
-version = "2.4.0"
+version = "2.4.1"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
diff --git a/scripts/docker b/scripts/docker
index f8787f9..ba68524 100755
--- a/scripts/docker
+++ b/scripts/docker
@@ -5,7 +5,11 @@ export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
cd "$NAVI_HOME"
+./scripts/action release x86_64-unknown-linux-musl
+
docker run \
-e HOMEBREW_NO_AUTO_UPDATE=1 \
- -it linuxbrew/alpine \
- bash -c 'brew install denisidoro/tools/navirs; bash'
+ -e HOMEBREW_NO_INSTALL_CLEANUP=1 \
+ -v "$(pwd):/navi" \
+ -it 'bashell/alpine-bash' \
+ bash -c 'apk add git; apk add curl; git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && yes | ln -s /navi/target/debug/navi /usr/local/bin/navi; source $HOME/.bashrc; bash'
diff --git a/src/flows/repo.rs b/src/flows/repo.rs
index c345976..ac111cf 100644
--- a/src/flows/repo.rs
+++ b/src/flows/repo.rs
@@ -50,7 +50,7 @@ pub fn add(uri: String) -> Result<(), Error> {
let tmp_path_str = filesystem::tmp_path_str()?;
let tmp_path_str_with_trailing_slash = format!("{}/", &tmp_path_str);
- filesystem::remove_dir(&tmp_path_str)?;
+ let _ = filesystem::remove_dir(&tmp_path_str);
filesystem::create_dir(&tmp_path_str)?;
eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
diff --git a/src/parser.rs b/src/parser.rs
index a8d40f1..8be2c51 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -3,10 +3,7 @@ use crate::filesystem;
use crate::structures::cheat::VariableMap;
use crate::structures::fnv::HashLine;
use crate::structures::fzf::{Opts as FzfOpts, SuggestionType};
-use crate::structures::{
- error::filesystem::{InvalidPath, UnreadableDir},
- option::Config,
-};
+use crate::structures::{error::filesystem::InvalidPath, option::Config};
use crate::welcome;
use anyhow::{Context, Error};
use regex::Regex;
@@ -226,21 +223,30 @@ pub fn read_all(
let mut variables = VariableMap::new();
let mut found_something = false;
let mut visited_lines = HashSet::new();
- let paths = filesystem::cheat_paths(config)?;
+ let paths = filesystem::cheat_paths(config);
+
+ if paths.is_err() {
+ welcome::cheatsheet(stdin);
+ return Ok(variables);
+ }
+
+ let paths = paths.expect("Unable to get paths");
let folders = paths_from_path_param(&paths);
for folder in folders {
if let Ok(dir_entries) = fs::read_dir(folder) {
for entry in dir_entries {
- let path = entry.map_err(|e| UnreadableDir::new(folder, e))?.path();
- let path_str = path
- .to_str()
- .ok_or_else(|| InvalidPath(path.to_path_buf()))?;
- if path_str.ends_with(".cheat")
- && read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
- && !found_something
- {
- found_something = true;
+ if entry.is_ok() {
+ let path = entry.expect("Impossible to read an invalid entry").path();
+ let path_str = path
+ .to_str()
+ .ok_or_else(|| InvalidPath(path.to_path_buf()))?;
+ if path_str.ends_with(".cheat")
+ && read_file(path_str, &mut variables, &mut visited_lines, stdin).is_ok()
+ && !found_something
+ {
+ found_something = true;
+ }
}
}
}