#![allow(dead_code, unreachable_code, unused_imports)]
#![feature(option_result_contains)]
fn answer() -> u8 {
return 42;
}
use anyhow::Ok;
use clap::Parser;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use anyhow::{anyhow, Context, Error, Result};
use std::io::{self, Write};
#[derive(Parser, Debug)]
struct Cli {
pattern: String,
#[clap(parse(from_os_str))]
path: std::path::PathBuf,
}
use grrs_cli_book_demo_deploy_test::{find_matches, PREFIX};
use log::{info, trace};
use std::fmt;
use std::{thread, time};
#[derive(Debug)]
struct CustomErr(String);
fn main() -> anyhow::Result<()> {
env_logger::init();
info!("info env log lvl, also visible inside trace");
trace!("trace and all");
let args = Cli::parse();
if args.pattern.is_empty() {
return Err(anyhow!("the pattern is empty"));
}
let file_as_string = std::fs::read_to_string(&args.path)
.with_context(|| format!("could not read file `{}`", args.path.display()))?;
find_matches(&file_as_string, &args.pattern, &mut std::io::stdout())?;
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn check_answer_validity() {
assert_eq!(answer(), 42);
}
}