Added parsing of command line args for config file path
parent
fe50f74723
commit
bdb7d766f4
|
@ -6,8 +6,8 @@ RUN cargo run
|
||||||
|
|
||||||
FROM rust:latest
|
FROM rust:latest
|
||||||
COPY --from=builder /target /target
|
COPY --from=builder /target /target
|
||||||
COPY --from=builder config.ini
|
COPY --from=builder config.ini config.ini
|
||||||
WORKDIR /target
|
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
|
HEALTHCHECK --interval=30s --timeout=30s --start-period=30s --retries=3 CMD curl --fail http://localhost:5000/health || exit 1
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#[allow(clippy::module_inception)]
|
#[allow(clippy::module_inception)]
|
||||||
pub mod bot {
|
pub mod bot {
|
||||||
|
|
||||||
use crate::{config_reader::config_reader::BotUserInfo, utils};
|
use crate::config_reader::config_reader::BotUserInfo;
|
||||||
use log::{info, debug};
|
use log::{info, debug};
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
Client,
|
Client,
|
||||||
|
|
|
@ -14,8 +14,7 @@ pub mod config_reader {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BotUserInfo {
|
impl BotUserInfo {
|
||||||
pub fn get_info(config_file_path: Option<&str>) -> Result<Self, Box<dyn Error>> {
|
pub fn get_info(config_file_path: &str) -> Result<Self, Box<dyn Error>> {
|
||||||
let config_file_path = config_file_path.unwrap_or("config.ini");
|
|
||||||
let mut config = Ini::new();
|
let mut config = Ini::new();
|
||||||
let _map = config.load(config_file_path)?;
|
let _map = config.load(config_file_path)?;
|
||||||
let user_id = config.get("credentials", "user_id").unwrap();
|
let user_id = config.get("credentials", "user_id").unwrap();
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -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]
|
#[tokio::main]
|
||||||
async fn 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue