Add command line option for config file
This commit is contained in:
parent
d21a66d887
commit
2acdda99ac
1 changed files with 9 additions and 1 deletions
10
src/main.rs
10
src/main.rs
|
@ -27,6 +27,10 @@ type ExitSender = oneshot::Sender<()>;
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(author, about)]
|
#[structopt(author, about)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
/// Config file
|
||||||
|
#[structopt(long = "config-file", short = "c")]
|
||||||
|
config_path: Option<PathBuf>,
|
||||||
|
|
||||||
/// The path to the log file. By default, does not log.
|
/// The path to the log file. By default, does not log.
|
||||||
#[structopt(long = "log-file")]
|
#[structopt(long = "log-file")]
|
||||||
log_file: Option<PathBuf>,
|
log_file: Option<PathBuf>,
|
||||||
|
@ -39,7 +43,11 @@ async fn main() -> Result<()> {
|
||||||
setup_logger(&opt)?;
|
setup_logger(&opt)?;
|
||||||
|
|
||||||
let config: Config = {
|
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();
|
let mut contents = Vec::new();
|
||||||
config_file.read_to_end(&mut contents)?;
|
config_file.read_to_end(&mut contents)?;
|
||||||
toml::from_slice(&contents)?
|
toml::from_slice(&contents)?
|
||||||
|
|
Loading…
Reference in a new issue