[web+lib] Apply some recommendations by @zethra

- #1 (comment)
  Import Serialize and Deserialize directly instead of qualifing.

- #1 (comment)
  Don't use Strings for paths. Use PathBuf instead.

- #1 (comment)
  Maybe return an error here since there server didn't actually start.
This commit is contained in:
Emi Simpson 2021-10-30 13:54:02 -04:00
parent 58d663c45f
commit 6d087bd155
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
3 changed files with 10 additions and 9 deletions

View File

@ -14,7 +14,7 @@ use crate::user_preferences::v0::UserPreferencesV0;
use crate::{InstanceSettings, Pronoun, WeightedTable};
use data_encoding::BASE32_NOPAD;
use serde;
use serde::{Serialize, Deserialize};
/// A user's preferences for the probabilities of certain pronouns
///
@ -28,7 +28,7 @@ use serde;
/// Because parsing a prefstring must be done in relation to an [`InstanceSettings`], the
/// `UserPreferences` struct shares a lifetime with the settings it was created with.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "Intermediary", into = "Intermediary")]
pub enum UserPreferences {
V0(v0::UserPreferencesV0)

View File

@ -1,3 +1,4 @@
use std::path::PathBuf;
use pronouns_today::PronounList;
use pronouns_today::UserPreferences;
use std::fs::OpenOptions;
@ -45,16 +46,16 @@ pub struct Run {
#[cfg_attr(feature = "docker",
argh(
option,
default = "String::from(\"/data/config.yml\")",
default = "PathBuf::from(\"/data/config.yml\")",
short = 'c'))]
#[cfg_attr(not(feature = "docker"),
argh(
option,
default = "String::from(\"/etc/pronouns_today.yml\")",
default = "PathBuf::from(\"/etc/pronouns_today.yml\")",
short = 'c'))]
/// path to the config file (generated if needed). Defaults to
/// /etc/pronouns_today.yml
pub config: String,
pub config: PathBuf,
#[argh(switch)]
/// don't attempt to read or generate a config file, just use command line args. Missing
@ -152,6 +153,6 @@ pub enum ConfigError {
/// The config file was missing, but has been created
///
/// The program should now prompt the user to fill the config in, and then exit. The
/// provided [`String`] contains the path to the new config file
ConfigCreated(String),
/// provided [`PathBuf`] contains the path to the new config file
ConfigCreated(PathBuf),
}

View File

@ -166,8 +166,8 @@ async fn main() -> std::io::Result<()> {
Err(ConfigError::ConfigCreated(path)) => {
println!("A config file has been generated at {}! Please check it out
and modify it to your liking, and then run this command
again", path);
exit(0);
again", path.display());
exit(1002);
}
};
log::info!("Starting with configuration {:?}", config);