From d78264a4fb247f448855edd0b5830073c72cd10c Mon Sep 17 00:00:00 2001 From: Aaron Johnon Date: Tue, 22 Apr 2025 16:46:19 -0500 Subject: [PATCH] Converted from YAML config to TOML --- src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1acc6a7..4b1e053 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ use std::path::PathBuf; use std::process; use std::time::Duration; +use toml; + type Result = std::result::Result>; #[derive(Debug, Deserialize)] @@ -27,12 +29,11 @@ fn main() -> Result<()> { let matches = Command::new("tbotsend") .version("development") .arg(Arg::new("config").short('f').long("config").value_name("FILE")) - .arg(Arg::new("chatid").short('c').long("chatid").value_name("chat_id")) - .arg(Arg::new("token").short('t').long("token").value_name("token")) + .arg(Arg::new("chatid").short('c').long("chatid").value_name("CHATID")) + .arg(Arg::new("token").short('t').long("token").value_name("TOKEN")) .arg(Arg::new("parse").short('p').long("parse").default_value("MarkdownV2").value_name("MODE")) .arg(Arg::new("timeout").long("timeout").value_parser(clap::value_parser!(u8)).default_value("10").value_name("SECONDS")) .arg(Arg::new("silent").short('s').long("silent").action(ArgAction::SetTrue)) - .arg(Arg::new("version").short('v').long("version").action(ArgAction::SetTrue)) .arg(Arg::new("help").short('h').long("help").action(ArgAction::Help)) .arg(Arg::new("message").num_args(1..).required(false)) .get_matches(); @@ -61,12 +62,12 @@ fn main() -> Result<()> { PathBuf::from(cfg) } else { dirs::home_dir() - .map(|p| p.join(".config/tbotsend.yaml")) + .map(|p| p.join(".config/tbotsend.toml")) .unwrap() }; let mut config_data = fs::read_to_string(&config_path).or_else(|_| { - let fallback = dirs::home_dir().unwrap().join(".tbotsend.yaml"); + let fallback = dirs::home_dir().unwrap().join(".tbotsend.toml"); fs::read_to_string(&fallback) }).map_err(|e| { print_error(&format!("Failed to read configuration file: {}", e)); @@ -74,11 +75,11 @@ fn main() -> Result<()> { })?; config_used = config_path.to_string_lossy().to_string(); - serde_yaml::from_str::(&mut config_data)? + toml::from_str::(&mut config_data)? }; if config.chat_id.is_empty() || config.token.is_empty() { - print_error("Configuration is missing ChatID or Token"); + print_error("Configuration is missing chat_id or token"); process::exit(2); }