Mainly refactored the help message into a re-usable constant

Signed-off-by: alexis-opolka <53085471+alexis-opolka@users.noreply.github.com>
This commit is contained in:
alexis-opolka 2025-05-13 19:54:15 +02:00
parent 652cf8d90b
commit f3248bb77a
3 changed files with 16 additions and 2 deletions

View file

@ -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;

View file

@ -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 {

View file

@ -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<String>) -> 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<String>) -> 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()