ares/config/mod.rs
1/// import general checker
2use lemmeknow::Identifier;
3use once_cell::sync::OnceCell;
4
5/// Library input is the default API input
6/// The CLI turns its arguments into a LibraryInput struct
7/// The Config object is a default configuration object
8/// For the entire program
9/// It's access using a variable like configuration
10/// ```rust
11/// use ares::config::get_config;
12/// let config = get_config();
13/// assert_eq!(config.verbose, 0);
14/// ```
15
16pub struct Config {
17 /// A level of verbosity to determine.
18 /// How much we print in logs.
19 pub verbose: u8,
20 /// The lemmeknow config to use
21 pub lemmeknow_config: Identifier,
22 /// Should the human checker be on?
23 /// This asks yes/no for plaintext. Turn off for API
24 pub human_checker_on: bool,
25 /// The timeout threshold before Ares quites
26 /// This is in seconds
27 pub timeout: u32,
28 /// Is the program being run in API mode?
29 /// This is used to determine if we should print to stdout
30 /// Or return the values
31 pub api_mode: bool,
32 /// Regex enables the user to search for a specific regex or crib
33 pub regex: Option<String>,
34}
35
36/// Cell for storing global Config
37static CONFIG: OnceCell<Config> = OnceCell::new();
38
39/// To initialize global config with custom values
40pub fn set_global_config(config: Config) {
41 CONFIG.set(config).ok(); // ok() used to make compiler happy about using Result
42}
43
44/// Get the global config.
45/// This will return default config if the config wasn't already initialized
46pub fn get_config() -> &'static Config {
47 CONFIG.get_or_init(Config::default)
48}
49
50/// Creates a default lemmeknow config
51const LEMMEKNOW_DEFAULT_CONFIG: Identifier = Identifier {
52 min_rarity: 0.0,
53 max_rarity: 0.0,
54 tags: vec![],
55 exclude_tags: vec![],
56 file_support: false,
57 boundaryless: false,
58};
59
60impl Default for Config {
61 fn default() -> Self {
62 Config {
63 verbose: 0,
64 lemmeknow_config: LEMMEKNOW_DEFAULT_CONFIG,
65 human_checker_on: false,
66 timeout: 5,
67 api_mode: true,
68 regex: None,
69 }
70 }
71}