From 92cf10d10a3af002f65e1721062ba020a8c45824 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sun, 15 Mar 2020 22:13:18 -0300 Subject: [PATCH] Allow repos with @ (#272) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmds/best.rs | 6 +++--- src/cmds/repo.rs | 16 ++++------------ src/filesystem.rs | 8 ++++++++ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 911d087e..fdef3687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -272,7 +272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "navi" -version = "2.1.0" +version = "2.1.1" dependencies = [ "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)", diff --git a/Cargo.toml b/Cargo.toml index ac290868..9e683230 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.1.0" +version = "2.1.1" authors = ["Denis Isidoro "] edition = "2018" description = "An interactive cheatsheet tool for the command-line" diff --git a/src/cmds/best.rs b/src/cmds/best.rs index aa8bf58e..ffce8fe2 100644 --- a/src/cmds/best.rs +++ b/src/cmds/best.rs @@ -4,9 +4,9 @@ use crate::option::Config; use std::error::Error; pub fn main(query: String, args: Vec, config: Config) -> Result<(), Box> { - if !args.is_empty() { - cmds::aux::abort("passing arguments to 'navi best'", 201) - } else { + if args.is_empty() { cmds::core::main(Variant::Filter(query), config, false) + } else { + cmds::aux::abort("passing arguments to 'navi best'", 201) } } diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index a362661a..a118fcea 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -7,16 +7,8 @@ use std::fs; use std::io::Write; use walkdir::WalkDir; -fn create_dir(path: &str) { - fs::create_dir_all(path).unwrap_or(()); -} - -fn remove_dir(path: &str) { - fs::remove_dir_all(path).unwrap_or(()); -} - pub fn add(uri: String) -> Result<(), Box> { - let actual_uri = if uri.contains("://") { + let actual_uri = if uri.contains("://") || uri.contains('@') { uri } else { format!("https://github.com/{}", uri) @@ -30,8 +22,8 @@ pub fn add(uri: String) -> Result<(), Box> { let tmp_path_str = format!("{}/tmp", cheat_path_str); let tmp_path_str_with_trailing_slash = format!("{}/", &tmp_path_str); - remove_dir(&tmp_path_str); - create_dir(&tmp_path_str); + filesystem::remove_dir(&tmp_path_str); + filesystem::create_dir(&tmp_path_str); eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str); @@ -76,7 +68,7 @@ pub fn add(uri: String) -> Result<(), Box> { fs::copy(from, to)?; } - remove_dir(&tmp_path_str); + filesystem::remove_dir(&tmp_path_str); eprintln!("The following .cheat files were imported successfully:\n{}\n\nThey are now located at {}\n\nPlease run navi again to check the results.", files, cheat_path_str); diff --git a/src/filesystem.rs b/src/filesystem.rs index 4f97bdb5..a6c79301 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -75,3 +75,11 @@ pub fn cheat_paths(config: &Config) -> String { .clone() .unwrap_or_else(cheat_paths_from_config_dir) } + +pub fn create_dir(path: &str) { + fs::create_dir_all(path).unwrap_or(()); +} + +pub fn remove_dir(path: &str) { + fs::remove_dir_all(path).unwrap_or(()); +}