fix: properly parse layers env var
parent
b3d1cec078
commit
5f6366078c
|
@ -2,7 +2,7 @@ mod backup;
|
|||
mod config;
|
||||
mod run;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use figment::{
|
||||
|
@ -83,7 +83,7 @@ impl Cli {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn config<T, U>(&self, args: &U) -> Result<T, figment::Error>
|
||||
pub fn config<T, U>(&self, args: &U) -> crate::Result<T>
|
||||
where
|
||||
T: Default + Serialize + for<'de> Deserialize<'de>,
|
||||
U: Serialize,
|
||||
|
@ -92,11 +92,28 @@ impl Cli {
|
|||
.config_file
|
||||
.clone()
|
||||
.unwrap_or(PathBuf::from(Env::var_or("ALEX_CONFIG_FILE", "")));
|
||||
Figment::new()
|
||||
|
||||
let mut figment = Figment::new()
|
||||
.merge(Serialized::defaults(T::default()))
|
||||
.merge(Toml::file(toml_file))
|
||||
.merge(Env::prefixed("ALEX_"))
|
||||
.merge(Serialized::defaults(args))
|
||||
.extract()
|
||||
.merge(Env::prefixed("ALEX_").ignore(&["ALEX_LAYERS"]));
|
||||
|
||||
// Layers need to be parsed separately, as the env var format is different than the one
|
||||
// serde expects
|
||||
if let Some(layers_env) = Env::var("ALEX_LAYERS") {
|
||||
let res = layers_env
|
||||
.split(';')
|
||||
.map(ManagerConfig::from_str)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if res.iter().any(|e| e.is_err()) {
|
||||
return Err(crate::other("Invalid layer configuration").into());
|
||||
}
|
||||
|
||||
let layers: Vec<_> = res.iter().flatten().collect();
|
||||
figment = figment.merge(Serialized::default("layers", layers));
|
||||
}
|
||||
|
||||
Ok(figment.merge(Serialized::defaults(args)).extract()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ fn backups_thread(server: Arc<server::ServerProcess>) {
|
|||
impl RunCli {
|
||||
pub fn run(&self, cli: &super::Cli, global: &super::Config) -> crate::Result<()> {
|
||||
let config: Config = cli.config(&self.args)?;
|
||||
println!("{:?}", config);
|
||||
|
||||
let (_, mut signals) = signals::install_signal_handlers()?;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
|
|||
use std::fmt;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ServerType {
|
||||
Unknown,
|
||||
Paper,
|
||||
|
|
Loading…
Reference in New Issue