Add option for usage without config
This commit is contained in:
parent
7764c5021e
commit
fc2ae6cf0a
@ -27,6 +27,10 @@ struct Options {
|
|||||||
#[structopt(short, long, value_name = "path", default_value = "/etc/noise-server/config.toml")]
|
#[structopt(short, long, value_name = "path", default_value = "/etc/noise-server/config.toml")]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
|
/// Don't use config
|
||||||
|
#[structopt(short = "C", long)]
|
||||||
|
no_config: bool,
|
||||||
|
|
||||||
/// Path to database
|
/// Path to database
|
||||||
#[structopt(short, long, value_name = "path", default_value = DEFAULT_DATABASE_PATH)]
|
#[structopt(short, long, value_name = "path", default_value = DEFAULT_DATABASE_PATH)]
|
||||||
database_path: PathBuf,
|
database_path: PathBuf,
|
||||||
@ -93,6 +97,9 @@ async fn load_sqlite_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_config(options: &Options) -> std::io::Result<Config> {
|
fn get_config(options: &Options) -> std::io::Result<Config> {
|
||||||
|
if options.no_config {
|
||||||
|
Ok(Config::default())
|
||||||
|
} else {
|
||||||
let mut config_file = File::open(&options.config)?;
|
let mut config_file = File::open(&options.config)?;
|
||||||
let mut config_string = String::new();
|
let mut config_string = String::new();
|
||||||
config_file.read_to_string(&mut config_string)?;
|
config_file.read_to_string(&mut config_string)?;
|
||||||
@ -103,4 +110,5 @@ fn get_config(options: &Options) -> std::io::Result<Config> {
|
|||||||
err
|
err
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user