Skip to content

Commit

Permalink
Fix: if command not found in cheatsh, report and return.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzvon committed Mar 12, 2021
1 parent 5d19464 commit 5da5c9a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/cheatsh.rs
Expand Up @@ -4,9 +4,14 @@ use crate::parser;
use crate::structures::cheat::VariableMap;
use anyhow::Context;
use anyhow::Error;
use regex::Regex;
use std::collections::HashSet;
use std::process::{self, Command, Stdio};

lazy_static! {
static ref UNKNOWN_TOPIC_REGEX: Regex = Regex::new(r"^Unknown topic\.").expect("Invalid regex");
}

fn map_line(line: &str) -> Result<String, Error> {
let line = line.trim().trim_end_matches(':');
Ok(line.to_string())
Expand All @@ -32,6 +37,19 @@ fn read_all(
) -> Result<Option<VariableMap>, Error> {
let mut variables = VariableMap::new();
let mut visited_lines = HashSet::new();

if UNKNOWN_TOPIC_REGEX.is_match(cheat) {
eprintln!(
"`{}` not found in cheatsh.
Output:
{}
",
query, cheat
);
process::exit(35)
}

parser::read_lines(
lines(query, cheat),
"cheat.sh",
Expand Down Expand Up @@ -69,9 +87,9 @@ Make sure wget is correctly installed."
if let Some(0) = out.status.code() {
} else {
eprintln!(
"Failed to call:
"Failed to call:
wget {}
Output:
{}
Expand Down

0 comments on commit 5da5c9a

Please sign in to comment.