Add option for generating default config

This commit is contained in:
Elias Schriefer 2021-07-08 12:55:48 +02:00
parent ef1c124395
commit 891f61f046

View File

@ -6,7 +6,10 @@ use std::{
boxed::Box, boxed::Box,
error::Error, error::Error,
}; };
use serde::Deserialize; use serde::{
Deserialize,
Serialize,
};
use sqlx::{ use sqlx::{
prelude::*, prelude::*,
sqlite::{ sqlite::{
@ -34,8 +37,13 @@ struct Options {
/// 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,
/// Prints default config
#[structopt(long)]
generate_config: bool,
} }
#[derive(Debug, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")] #[serde(default, rename_all = "kebab-case")]
struct Config { struct Config {
database_path: PathBuf, database_path: PathBuf,
@ -54,6 +62,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let clap_matches = Options::clap().get_matches(); let clap_matches = Options::clap().get_matches();
let options = Options::from_clap(&clap_matches); let options = Options::from_clap(&clap_matches);
if options.generate_config {
println!("{}", toml::to_string_pretty(&Config::default())?);
return Ok(());
}
let mut config = get_config(&options)?; let mut config = get_config(&options)?;
if let Some(db_path) = clap_matches.value_of("database_path") { if let Some(db_path) = clap_matches.value_of("database_path") {
@ -109,5 +122,5 @@ fn get_config(options: &Options) -> std::io::Result<Config> {
err err
) )
) )
} }
} }