From f3248bb77a01ab286d38004ed3cdc44fabe3d3d2 Mon Sep 17 00:00:00 2001 From: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com> Date: Tue, 13 May 2025 19:54:15 +0200 Subject: [PATCH] Mainly refactored the help message into a re-usable constant Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com> --- src/commands/repo/list.rs | 5 +++-- src/commands/repo/mod.rs | 2 ++ src/commands/repo/sync.rs | 11 +++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/commands/repo/list.rs b/src/commands/repo/list.rs index 19dc8ba..e2d701b 100644 --- a/src/commands/repo/list.rs +++ b/src/commands/repo/list.rs @@ -1,6 +1,8 @@ use crate::filesystem::local_cheatsheet_repositories; use crate::libs::terminal::hyperlink; +use crate::commands::repo::HELP_NO_REPOSITORIES_FOUND; + pub fn main() { let (cheats_repos, cheats_paths) = local_cheatsheet_repositories(); @@ -9,8 +11,7 @@ pub fn main() { // We do have entries -> We show them // We do not have entries -> We put a message for the user to add one if cheats_repos.is_empty() { - eprintln!("Uh Oh! It seems you haven't downloaded a cheatsheet repository yet."); - eprintln!("What you can do: \n\n- `navi repo add` to add a cheatsheet repository\n- `navi repo browse` to browse recommended cheatsheet repositories"); + eprintln!("{}", HELP_NO_REPOSITORIES_FOUND); // We quit this function return; diff --git a/src/commands/repo/mod.rs b/src/commands/repo/mod.rs index a14e2d6..e1f4b97 100644 --- a/src/commands/repo/mod.rs +++ b/src/commands/repo/mod.rs @@ -34,6 +34,8 @@ pub struct Input { pub cmd: RepoCommand, } +pub const HELP_NO_REPOSITORIES_FOUND: &str = "Uh Oh! It seems you haven't downloaded a cheatsheet repository yet.\nWhat you can do: \n\n- `navi repo add` to add a cheatsheet repository\n- `navi repo browse` to browse recommended cheatsheet repositories"; + impl Runnable for Input { fn run(&self) -> Result<()> { match &self.cmd { diff --git a/src/commands/repo/sync.rs b/src/commands/repo/sync.rs index 41e04c9..76de30e 100644 --- a/src/commands/repo/sync.rs +++ b/src/commands/repo/sync.rs @@ -4,9 +4,17 @@ use crate::common::git; use crate::filesystem::{all_cheat_files, all_git_files, local_cheatsheet_repositories}; use crate::prelude::*; +use crate::commands::repo::HELP_NO_REPOSITORIES_FOUND; + pub fn main(name: Option) -> Result<()> { let (cheats_repo_uris, cheats_repo_paths) = local_cheatsheet_repositories(); + if cheats_repo_paths.is_empty() { + eprintln!("{}", HELP_NO_REPOSITORIES_FOUND); + + return Ok(()); + } + if name.clone().is_some() { let name = name.clone().unwrap(); @@ -52,6 +60,9 @@ pub fn main(name: Option) -> Result<()> { // // They need to be removed and the cheat files renamed. + // TODO: A note to be remembered, the filter needs to be adjusted to take everything we do not want + // want to keep (i.e. anything that is not a git file nor a cheat file) + let files_to_discard = WalkDir::new(&cheat_repo) .follow_links(true) .into_iter()