From 91569199408b9f4375a0a3bf5df1834fc7263e89 Mon Sep 17 00:00:00 2001 From: figsoda Date: Wed, 15 Mar 2023 22:04:41 -0400 Subject: [PATCH] fix(cheat): abort when no cheat sheet found for the command --- src/error.rs | 3 +++ src/helper/docs/cheat.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/error.rs b/src/error.rs index a68d2ca..ffb4479 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,6 +15,9 @@ pub enum Error { /// Error that might occur when running on unsupported platforms. #[error("Unsupported platform.")] UnsupportedPlatformError, + /// Error that might occur when trying to show the cheat sheet + #[error("No cheat sheet found for `{0}`")] + CheatSheetNotFoundError(String), } /// Type alias for the standard [`Result`] type. diff --git a/src/helper/docs/cheat.rs b/src/helper/docs/cheat.rs index 3391f26..08b25da 100644 --- a/src/helper/docs/cheat.rs +++ b/src/helper/docs/cheat.rs @@ -25,6 +25,9 @@ pub fn show_cheat_sheet( .call() .map_err(|e| Error::from(Box::new(e)))? .into_string()?; + if cheat_sheet.starts_with("Unknown topic.") { + return Err(Error::CheatSheetNotFoundError(cmd.into())); + } if let Some(pager) = pager { let mut process = if cfg!(target_os = "windows") { Command::new("cmd")