Allow repos with @ (#272)

This commit is contained in:
Denis Isidoro 2020-03-15 22:13:18 -03:00 committed by GitHub
parent 672fcc0c69
commit 92cf10d10a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 17 deletions

2
Cargo.lock generated
View file

@ -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)",

View file

@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.1.0"
version = "2.1.1"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"

View file

@ -4,9 +4,9 @@ use crate::option::Config;
use std::error::Error;
pub fn main(query: String, args: Vec<String>, config: Config) -> Result<(), Box<dyn Error>> {
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)
}
}

View file

@ -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<dyn Error>> {
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<dyn Error>> {
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<dyn Error>> {
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);

View file

@ -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(());
}