#![forbid(unsafe_code)]
#![warn(clippy::pedantic, clippy::cargo)]
#![allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::missing_errors_doc,
clippy::missing_panics_doc
)]
use std::{error::Error, ops::ControlFlow, result};
use argh::FromArgs;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
pub mod game;
pub mod providers;
pub mod terminal;
use crate::{game::Game, terminal::ThemeStyle};
pub type Result<T> = result::Result<T, Box<dyn Error + Send + Sync>>;
#[derive(FromArgs)]
pub struct Args {
#[argh(short = 't', option)]
token: Option<String>,
#[argh(short = 'p', option)]
provider: Option<String>,
#[argh(short = 'w', option, default = "1500")]
wait: u64,
#[argh(short = 's', switch)]
shuffle: bool,
#[argh(option)]
theme: Option<String>,
}
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct Config {
high_score: u32,
token: String,
theme: Option<ThemeStyle>,
}
lazy_static! {
pub static ref ARGS: Args = argh::from_env();
pub static ref CONFIG: Config = confy::load("guess-that-lang").unwrap();
}
pub fn main() -> Result<()> {
let mut game = Game::new()?;
let mut result = game.start_new_round(None)?;
while let ControlFlow::Continue(_) = result {
result = game.start_next_round()?;
}
Ok(())
}