From 2acdda99acd5cf10c5a1936be7d729a59d7ad986 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 12 Feb 2021 10:04:41 -0600 Subject: [PATCH] Add command line option for config file --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 11639b8..18aca46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,10 @@ type ExitSender = oneshot::Sender<()>; #[derive(Debug, StructOpt)] #[structopt(author, about)] struct Opt { + /// Config file + #[structopt(long = "config-file", short = "c")] + config_path: Option, + /// The path to the log file. By default, does not log. #[structopt(long = "log-file")] log_file: Option, @@ -39,7 +43,11 @@ async fn main() -> Result<()> { setup_logger(&opt)?; let config: Config = { - let mut config_file = File::open("config.toml")?; + let config_path = opt + .config_path + .clone() + .unwrap_or_else(|| "config.toml".into()); + let mut config_file = File::open(config_path)?; let mut contents = Vec::new(); config_file.read_to_end(&mut contents)?; toml::from_slice(&contents)?