Skip to content

Commit

Permalink
Allow repos with @ (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Mar 16, 2020
1 parent 672fcc0 commit 92cf10d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.1.0"
version = "2.1.1"
authors = ["Denis Isidoro <[email protected]>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
Expand Down
6 changes: 3 additions & 3 deletions src/cmds/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 4 additions & 12 deletions src/cmds/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}

0 comments on commit 92cf10d

Please sign in to comment.