mirror of
https://github.com/denisidoro/navi.git
synced 2026-01-23 02:14:19 +00:00
Fixes some small issues
Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
parent
f3248bb77a
commit
85ed5e8b05
5 changed files with 26 additions and 11 deletions
|
|
@ -32,7 +32,7 @@ fn ask_folder_present_question(finder: &FinderChoice) -> Result<bool> {
|
|||
finder_yes_no_question(finder, opts)
|
||||
}
|
||||
|
||||
pub fn main(uri: String, yes_flag: bool) -> Result<()> {
|
||||
pub fn main(uri: String, yes_flag: bool, &branch: Option<String>) -> Result<()> {
|
||||
let finder = CONFIG.finder();
|
||||
|
||||
// If the user has set the yes flag, we don't ask a confirmation
|
||||
|
|
@ -72,7 +72,7 @@ pub fn main(uri: String, yes_flag: bool) -> Result<()> {
|
|||
|
||||
eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
|
||||
|
||||
git::shallow_clone(actual_uri.as_str(), tmp_path_str)
|
||||
git::shallow_clone(actual_uri.as_str(), tmp_path_str, &branch)
|
||||
.with_context(|| format!("Failed to clone `{actual_uri}`"))?;
|
||||
|
||||
let all_files = all_cheat_files(&tmp_pathbuf).join("\n");
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub fn main() -> Result<String> {
|
|||
filesystem::create_dir(&repo_pathbuf)?;
|
||||
|
||||
let (repo_url, _, _) = git::meta("denisidoro/cheats");
|
||||
git::shallow_clone(repo_url.as_str(), repo_path_str)
|
||||
git::shallow_clone(repo_url.as_str(), repo_path_str, None)
|
||||
.with_context(|| format!("Failed to clone `{repo_url}`"))?;
|
||||
|
||||
let feature_repos_file = {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ pub enum RepoCommand {
|
|||
/// Assumes yes for all confirmations
|
||||
#[clap(short = 'y', long = "yes")]
|
||||
yes_flag: bool,
|
||||
|
||||
/// Lets you target a specific git ref (e.g. a commit or a branch), anything accepted by the `--branch` parameter of `git-clone`
|
||||
#[clap(short = 'b', long = "branch")]
|
||||
branch: Option<String>,
|
||||
},
|
||||
/// Synchronize either all cheatsheet repositories or a given one.
|
||||
Sync {
|
||||
|
|
@ -39,15 +43,15 @@ pub const HELP_NO_REPOSITORIES_FOUND: &str = "Uh Oh! It seems you haven't downlo
|
|||
impl Runnable for Input {
|
||||
fn run(&self) -> Result<()> {
|
||||
match &self.cmd {
|
||||
RepoCommand::Add { uri, yes_flag } => {
|
||||
add::main(uri.clone(), *yes_flag)
|
||||
RepoCommand::Add { uri, yes_flag, branch } => {
|
||||
add::main(uri.clone(), *yes_flag, &branch)
|
||||
.with_context(|| format!("Failed to import cheatsheets from `{uri}`"))?;
|
||||
|
||||
commands::core::main()
|
||||
}
|
||||
RepoCommand::Browse => {
|
||||
let repo = browse::main().context("Failed to browse featured cheatsheets")?;
|
||||
add::main(repo.clone(), false)
|
||||
add::main(repo.clone(), false, None)
|
||||
.with_context(|| format!("Failed to import cheatsheets from `{repo}`"))?;
|
||||
|
||||
commands::core::main()
|
||||
|
|
|
|||
|
|
@ -70,11 +70,13 @@ pub fn main(name: Option<String>) -> Result<()> {
|
|||
.map(|e| {
|
||||
let path_str = e.path().to_str().unwrap_or("").to_string();
|
||||
|
||||
if ! cheat_files.contains(&path_str) {
|
||||
return e.path().to_str().unwrap_or("").to_string()
|
||||
if cheat_files.contains(&path_str) {
|
||||
eprintln!("CHEAT: {}", &path_str);
|
||||
|
||||
return "".to_string()
|
||||
}
|
||||
|
||||
return "".to_string()
|
||||
return e.path().to_str().unwrap_or("").to_string()
|
||||
})
|
||||
.filter(|e| e.ends_with(".cheat") || e.ends_with(".cheat.md"))
|
||||
.collect::<Vec<String>>();
|
||||
|
|
|
|||
|
|
@ -2,9 +2,18 @@ use crate::common::shell::ShellSpawnError;
|
|||
use crate::prelude::*;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn shallow_clone(uri: &str, target: &str) -> Result<()> {
|
||||
pub fn shallow_clone(uri: &str, target: &str, branch: &Option<String>) -> Result<()> {
|
||||
// If we target a specific ref, we add the parameter inside the arguments to call
|
||||
// git with.
|
||||
|
||||
let git_clone_args = if branch.is_some() {
|
||||
["clone", uri, target, "--depth", "1", "--branch", branch.unwrap().as_str()]
|
||||
} else {
|
||||
["clone", uri, target, "--depth", "1", "", ""]
|
||||
};
|
||||
|
||||
Command::new("git")
|
||||
.args(["clone", uri, target, "--depth", "1"])
|
||||
.args(git_clone_args)
|
||||
.spawn()
|
||||
.map_err(|e| ShellSpawnError::new("git clone", e))?
|
||||
.wait()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue