SolarEnergy/custom_consumption/src/app_config.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2024-06-30 20:54:23 +00:00
use clap::Parser;
use std::path::{Path, PathBuf};
/// Solar system central backend
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct AppConfig {
/// The path to the file to write to update the value
#[clap(short, long, default_value = "/dev/shm/consumption.txt")]
file_path: String,
/// Minimal value
#[clap( long, default_value_t = -5000)]
pub min: i64,
/// Maximal value
#[clap(long, default_value_t = 5000)]
pub max: i64,
/// Minimum interval between two persistence (milliseconds)
#[clap(long, default_value_t = 500)]
pub min_save_interval: u128,
2024-06-30 20:54:23 +00:00
}
lazy_static::lazy_static! {
static ref ARGS: AppConfig = {
AppConfig::parse()
};
}
impl AppConfig {
/// Get parsed command line arguments
pub fn get() -> &'static AppConfig {
&ARGS
}
/// Path to the file to update the value
pub fn file_path(&self) -> PathBuf {
Path::new(&self.file_path).to_path_buf()
}
}
#[cfg(test)]
mod test {
use crate::app_config::AppConfig;
#[test]
fn verify_cli() {
use clap::CommandFactory;
AppConfig::command().debug_assert()
}
}