[web] Add support for specifying pronouns via the command line

This commit is contained in:
Emi Simpson 2021-10-30 12:08:12 -04:00
parent 1e78a528ce
commit 2aeffefee5
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -1,3 +1,4 @@
use pronouns_today::PronounList;
use pronouns_today::UserPreferences;
use std::fs::OpenOptions;
use std::fs::File;
@ -68,6 +69,12 @@ pub struct Run {
/// default pronoun probabilites (formatted as a prefstring, like the ones in the
/// used in the custom URLs, e.g. "acaqeawdym")
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 {
@ -76,7 +83,7 @@ impl Run {
/// 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
/// 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 {
match File::open(&self.config) {
Ok(raw_cfg) => {
@ -100,7 +107,7 @@ impl Run {
}
} else {
Ok(Conf::default())
}.map(|config| config.update_with(&self))
}.map(|config| config.update_with(self))
}
}
@ -117,8 +124,9 @@ pub struct 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.instance_settings.pronoun_list = args.pronouns.map(Into::into).unwrap_or(self.instance_settings.pronoun_list);
self
}
}