mod core;
use std::string::String;
use clap::{value_parser, Arg, Command};
use crate::core::jokes::get_joke;
fn main()
{
let matches = Command::new("cmd")
.subcommand(Command::new("joke")
.about("Get a joke")
.arg(
Arg::new("contains")
.short('r')
.long("joke")
.required(true)
.help("A joke will be given to you for the contains key word")
.value_parser(value_parser!(String))
)
.arg(
Arg::new("category")
.short('c')
.long("category")
.required(true)
.help("Search a joke in a category")
.value_parser(value_parser!(String))
)
.arg(
Arg::new("racist")
.long("racist")
.required(false)
.help("Should the joke be racists")
.default_value("false")
.value_parser(value_parser!(bool))
)
.arg(
Arg::new("sexist")
.long("sexist")
.required(false)
.default_value("false")
.help("Should the joke be sexist")
.value_parser(value_parser!(bool))
)
.arg(
Arg::new("religious")
.long("religious")
.required(false)
.default_value("false")
.help("Should the joke be religious")
.value_parser(value_parser!(bool))
)
)
.arg_required_else_help(true)
.about("Get a joke for you man")
.get_matches();
let result = match matches.subcommand_matches("joke")
{
Some(joke) =>
{
let contains = joke.get_one::<String>("contains").unwrap();
let category = joke.get_one::<String>("category").unwrap();
let racist = joke.get_one::<bool>("racist").unwrap_or(&false);
let sexist = joke.get_one::<bool>("sexist").unwrap_or(&false);
let religious = joke.get_one::<bool>("religious").unwrap_or(&false);
get_joke(&category, &racist, &sexist, &religious, &contains).unwrap_or_else(|error| format!("{}", error))
}
None => {
"Invalid Cli command was passed".to_string()
}
};
println!("{}", result);
}