From 7da5b5ce46dabf0e2c13c48df076fadddda33d34 Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 21 Jun 2024 04:44:19 +0900 Subject: [PATCH] only validate latest config files --- src/command/config/validate.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/command/config/validate.rs b/src/command/config/validate.rs index fc1980e..97ef002 100644 --- a/src/command/config/validate.rs +++ b/src/command/config/validate.rs @@ -1,6 +1,9 @@ //! `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 std::{fs, io::Read}; use validator::Validate; @@ -9,6 +12,10 @@ use validator::Validate; pub(crate) enum ValidationError { #[error(transparent)] ReadFile(#[from] std::io::Error), + #[error(transparent)] + UnknownRevision(#[from] RevisionCheckError), + #[error("config files are not the latest revision")] + OutOfDate, #[error("invalid config file")] InvalidConfig, } @@ -22,6 +29,13 @@ enum ReadError { } pub(super) fn run() -> Result<(), ValidationError> { + if next_revision()?.is_some() { + cprintln!( + "Please first run `fishctl config migrate` to update your config files." + ); + return Err(ValidationError::OutOfDate); + } + let server_validation_result = match read_server_toml() { Ok(config) => config.validate().map_err(|err| { cprintln!("config/server.toml is invalid.\n{}", err);