[web] Add support for specifying pronouns via the command line
This commit is contained in:
parent
1e78a528ce
commit
2aeffefee5
|
@ -1,3 +1,4 @@
|
||||||
|
use pronouns_today::PronounList;
|
||||||
use pronouns_today::UserPreferences;
|
use pronouns_today::UserPreferences;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -68,6 +69,12 @@ pub struct Run {
|
||||||
/// default pronoun probabilites (formatted as a prefstring, like the ones in the
|
/// default pronoun probabilites (formatted as a prefstring, like the ones in the
|
||||||
/// used in the custom URLs, e.g. "acaqeawdym")
|
/// used in the custom URLs, e.g. "acaqeawdym")
|
||||||
pub default_prefstr: Option<UserPreferences>,
|
pub default_prefstr: Option<UserPreferences>,
|
||||||
|
|
||||||
|
#[argh(option)]
|
||||||
|
/// the pronouns to be supported by the server. see configuration file documentation
|
||||||
|
/// for warnings when changing this value. formatted as a list of comma seperated
|
||||||
|
/// five-form pronouns, e.g. she/her/her/hers/herself,he/him/his/his/himself
|
||||||
|
pub pronouns: Option<PronounList>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Run {
|
impl Run {
|
||||||
|
@ -76,7 +83,7 @@ impl Run {
|
||||||
/// If `--no-read-cfg` was passed, no config file is present, and there aren't
|
/// If `--no-read-cfg` was passed, no config file is present, and there aren't
|
||||||
/// enough args to populate the configuration, returns an [`Err`] with a list of
|
/// enough args to populate the configuration, returns an [`Err`] with a list of
|
||||||
/// arguments that were missing.
|
/// arguments that were missing.
|
||||||
pub fn load_config(&self) -> Result<Conf, ConfigError> {
|
pub fn load_config(self) -> Result<Conf, ConfigError> {
|
||||||
if !self.no_read_cfg {
|
if !self.no_read_cfg {
|
||||||
match File::open(&self.config) {
|
match File::open(&self.config) {
|
||||||
Ok(raw_cfg) => {
|
Ok(raw_cfg) => {
|
||||||
|
@ -100,7 +107,7 @@ impl Run {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(Conf::default())
|
Ok(Conf::default())
|
||||||
}.map(|config| config.update_with(&self))
|
}.map(|config| config.update_with(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +124,9 @@ pub struct Conf {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Conf {
|
impl Conf {
|
||||||
fn update_with(mut self, args: &Run) -> Conf {
|
fn update_with(mut self, args: Run) -> Conf {
|
||||||
self.port = args.port.unwrap_or(self.port);
|
self.port = args.port.unwrap_or(self.port);
|
||||||
|
self.instance_settings.pronoun_list = args.pronouns.map(Into::into).unwrap_or(self.instance_settings.pronoun_list);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue