only validate latest config files

This commit is contained in:
naskya 2024-06-21 04:44:19 +09:00
parent 3a57eb5880
commit 7da5b5ce46
Signed by: naskya
GPG key ID: 712D413B3A9FED5C

View file

@ -1,6 +1,9 @@
//! `config validate` subcommand //! `config validate` subcommand
use crate::config::{client, server, CLIENT_CONFIG_PATH, SERVER_CONFIG_PATH}; use crate::{
command::config::{next_revision, RevisionCheckError},
config::{client, server, CLIENT_CONFIG_PATH, SERVER_CONFIG_PATH},
};
use color_print::cprintln; use color_print::cprintln;
use std::{fs, io::Read}; use std::{fs, io::Read};
use validator::Validate; use validator::Validate;
@ -9,6 +12,10 @@ use validator::Validate;
pub(crate) enum ValidationError { pub(crate) enum ValidationError {
#[error(transparent)] #[error(transparent)]
ReadFile(#[from] std::io::Error), ReadFile(#[from] std::io::Error),
#[error(transparent)]
UnknownRevision(#[from] RevisionCheckError),
#[error("config files are not the latest revision")]
OutOfDate,
#[error("invalid config file")] #[error("invalid config file")]
InvalidConfig, InvalidConfig,
} }
@ -22,6 +29,13 @@ enum ReadError {
} }
pub(super) fn run() -> Result<(), ValidationError> { pub(super) fn run() -> Result<(), ValidationError> {
if next_revision()?.is_some() {
cprintln!(
"Please first run `<bold>fishctl config migrate</>` to update your config files."
);
return Err(ValidationError::OutOfDate);
}
let server_validation_result = match read_server_toml() { let server_validation_result = match read_server_toml() {
Ok(config) => config.validate().map_err(|err| { Ok(config) => config.validate().map_err(|err| {
cprintln!("<r!><bold>config/server.toml is invalid.</></>\n{}", err); cprintln!("<r!><bold>config/server.toml is invalid.</></>\n{}", err);