[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:
parent
58d663c45f
commit
6d087bd155
|
@ -14,7 +14,7 @@ use crate::user_preferences::v0::UserPreferencesV0;
|
||||||
use crate::{InstanceSettings, Pronoun, WeightedTable};
|
use crate::{InstanceSettings, Pronoun, WeightedTable};
|
||||||
|
|
||||||
use data_encoding::BASE32_NOPAD;
|
use data_encoding::BASE32_NOPAD;
|
||||||
use serde;
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
/// A user's preferences for the probabilities of certain pronouns
|
/// 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
|
/// 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.
|
/// `UserPreferences` struct shares a lifetime with the settings it was created with.
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(try_from = "Intermediary", into = "Intermediary")]
|
#[serde(try_from = "Intermediary", into = "Intermediary")]
|
||||||
pub enum UserPreferences {
|
pub enum UserPreferences {
|
||||||
V0(v0::UserPreferencesV0)
|
V0(v0::UserPreferencesV0)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
use pronouns_today::PronounList;
|
use pronouns_today::PronounList;
|
||||||
use pronouns_today::UserPreferences;
|
use pronouns_today::UserPreferences;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
|
@ -45,16 +46,16 @@ pub struct Run {
|
||||||
#[cfg_attr(feature = "docker",
|
#[cfg_attr(feature = "docker",
|
||||||
argh(
|
argh(
|
||||||
option,
|
option,
|
||||||
default = "String::from(\"/data/config.yml\")",
|
default = "PathBuf::from(\"/data/config.yml\")",
|
||||||
short = 'c'))]
|
short = 'c'))]
|
||||||
#[cfg_attr(not(feature = "docker"),
|
#[cfg_attr(not(feature = "docker"),
|
||||||
argh(
|
argh(
|
||||||
option,
|
option,
|
||||||
default = "String::from(\"/etc/pronouns_today.yml\")",
|
default = "PathBuf::from(\"/etc/pronouns_today.yml\")",
|
||||||
short = 'c'))]
|
short = 'c'))]
|
||||||
/// path to the config file (generated if needed). Defaults to
|
/// path to the config file (generated if needed). Defaults to
|
||||||
/// /etc/pronouns_today.yml
|
/// /etc/pronouns_today.yml
|
||||||
pub config: String,
|
pub config: PathBuf,
|
||||||
|
|
||||||
#[argh(switch)]
|
#[argh(switch)]
|
||||||
/// don't attempt to read or generate a config file, just use command line args. Missing
|
/// 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 config file was missing, but has been created
|
||||||
///
|
///
|
||||||
/// The program should now prompt the user to fill the config in, and then exit. The
|
/// 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
|
/// provided [`PathBuf`] contains the path to the new config file
|
||||||
ConfigCreated(String),
|
ConfigCreated(PathBuf),
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,8 +166,8 @@ async fn main() -> std::io::Result<()> {
|
||||||
Err(ConfigError::ConfigCreated(path)) => {
|
Err(ConfigError::ConfigCreated(path)) => {
|
||||||
println!("A config file has been generated at {}! Please check it out
|
println!("A config file has been generated at {}! Please check it out
|
||||||
and modify it to your liking, and then run this command
|
and modify it to your liking, and then run this command
|
||||||
again", path);
|
again", path.display());
|
||||||
exit(0);
|
exit(1002);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
log::info!("Starting with configuration {:?}", config);
|
log::info!("Starting with configuration {:?}", config);
|
||||||
|
|
Loading…
Reference in New Issue