aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/input
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-05-12 09:42:05 +0200
committera-kenji <aks.kenji@protonmail.com>2021-05-12 09:57:47 +0200
commit6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6 (patch)
tree47d16f195a9cb7e26750fcadb51f61a41e96788b /src/common/input
parentdocs(changelog): Add Option for Simplified Layout (diff)
downloadsl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.tar.gz
sl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.tar.xz
sl0ppij-6ffd698d0a1a974f0cb80cb256f4d58e2c3d97f6.zip
Slight rework of config loading.
Merges the cli and file configuration
Diffstat (limited to 'src/common/input')
-rw-r--r--src/common/input/options.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/common/input/options.rs b/src/common/input/options.rs
index 3ff2fd8e..3bd3fc31 100644
--- a/src/common/input/options.rs
+++ b/src/common/input/options.rs
@@ -1,12 +1,23 @@
+//! Handles cli and configuration options
+use crate::cli::ConfigCli;
use serde::{Deserialize, Serialize};
use structopt::StructOpt;
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
/// Options that can be set either through the config file,
/// or cli flags
+/// intermediate struct
pub struct Options {
- /// Allow plugins to use a more compatible font type
+ /// Allow plugins to use a more simplified layout
+ /// that is compatible with more fonts
#[structopt(long)]
+ pub simplified_ui: Option<bool>,
+}
+
+#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize)]
+/// Merged version of the [`Options`] struct
+// TODO: Maybe a good candidate for a macro?
+pub struct ConfigOptions {
pub simplified_ui: bool,
}
@@ -18,4 +29,35 @@ impl Options {
Options::default()
}
}
+
+ /// Merges two [`Options`] structs, a `Some` in `other`
+ /// will supercede a `Some` in `self`
+ // TODO: Maybe a good candidate for a macro?
+ pub fn merge(&self, other: Options) -> Options {
+ let simplified_ui = if let Some(bool) = other.simplified_ui {
+ Some(bool)
+ } else {
+ self.simplified_ui
+ };
+
+ Options { simplified_ui }
+ }
+
+ pub fn from_cli(&self, other: Option<ConfigCli>) -> Options {
+ if let Some(ConfigCli::Options(options)) = other {
+ Options::merge(&self, options)
+ } else {
+ self.to_owned()
+ }
+ }
+}
+
+impl From<Options> for ConfigOptions {
+ fn from(options: Options) -> ConfigOptions {
+ let simplified_ui = options.simplified_ui;
+
+ ConfigOptions {
+ simplified_ui: simplified_ui.unwrap_or_default(),
+ }
+ }
}