Added parsing of command line args for config file path

main
David 2022-12-29 20:45:25 +01:00
parent fe50f74723
commit bdb7d766f4
4 changed files with 19 additions and 6 deletions

View File

@ -6,8 +6,8 @@ RUN cargo run
FROM rust:latest
COPY --from=builder /target /target
COPY --from=builder config.ini
COPY --from=builder config.ini config.ini
WORKDIR /target
RUN ./matrix-modbot
RUN ./matrix-modbot config.ini
HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD curl --fail http://localhost:5000/health || exit 1

View File

@ -1,7 +1,7 @@
#[allow(clippy::module_inception)]
pub mod bot {
use crate::{config_reader::config_reader::BotUserInfo, utils};
use crate::config_reader::config_reader::BotUserInfo;
use log::{info, debug};
use matrix_sdk::{
Client,

View File

@ -14,8 +14,7 @@ pub mod config_reader {
}
impl BotUserInfo {
pub fn get_info(config_file_path: Option<&str>) -> Result<Self, Box<dyn Error>> {
let config_file_path = config_file_path.unwrap_or("config.ini");
pub fn get_info(config_file_path: &str) -> Result<Self, Box<dyn Error>> {
let mut config = Ini::new();
let _map = config.load(config_file_path)?;
let user_id = config.get("credentials", "user_id").unwrap();

View File

@ -1,4 +1,18 @@
use std::env;
mod config_reader;
mod bot;
pub use config_reader::config_reader::BotUserInfo;
pub use bot::bot::Bot;
#[tokio::main]
async fn main() {
println!("Hello, world!");
println!("Starting Matrix-Modbot");
let mut args: Vec<String> = env::args().collect();
if args.is_empty() {
args.push("config.ini".to_string()) // Set the default config file path to config.ini
}
let config_path = &args[0];
let creds = BotUserInfo::get_info(config_path).unwrap();
Bot::bot_login(creds);
}