From 9b4262b9964ca9e68cc8788a6d19ad56d04b3e49 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Fri, 9 Jul 2021 10:02:59 +0200 Subject: [PATCH] Move Options into its own module --- src/cli.rs | 21 +++++++++++++++++++++ src/main.rs | 22 +++------------------- 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 src/cli.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..c853a90 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,21 @@ +use structopt::StructOpt; +use std::path::PathBuf; + +#[derive(Debug, StructOpt)] +pub struct Options { + /// Path to config + #[structopt(short, long, value_name = "path", default_value = "/etc/noise-server/config.toml")] + pub config: PathBuf, + + /// Don't use config + #[structopt(short = "C", long)] + pub no_config: bool, + + /// Path to database + #[structopt(short, long, value_name = "path", default_value = crate::DEFAULT_DATABASE_PATH)] + pub database_path: PathBuf, + + /// Prints default config + #[structopt(long)] + pub generate_config: bool, +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 60fd468..ace0340 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,28 +21,12 @@ use tokio::{ fs::File, io::AsyncReadExt, }; +use crate::cli::Options; + +mod cli; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; -#[derive(Debug, StructOpt)] -struct Options { - /// Path to config - #[structopt(short, long, value_name = "path", default_value = "/etc/noise-server/config.toml")] - config: PathBuf, - - /// Don't use config - #[structopt(short = "C", long)] - no_config: bool, - - /// Path to database - #[structopt(short, long, value_name = "path", default_value = DEFAULT_DATABASE_PATH)] - database_path: PathBuf, - - /// Prints default config - #[structopt(long)] - generate_config: bool, -} - #[derive(Debug, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] struct Config {