diff --git a/src/command/config.rs b/src/command/config.rs index c9853e6..e87ac6d 100644 --- a/src/command/config.rs +++ b/src/command/config.rs @@ -3,22 +3,17 @@ mod migrate; mod validate; -use clap::{Subcommand, ValueEnum}; +use crate::config::Revision; +use clap::Subcommand; #[derive(Subcommand)] pub(crate) enum Commands { /// Convert an old config file into the new format - Migrate { revision: ConfigRevision }, + Migrate { revision: Revision }, /// Validate the config file Validate, } -#[derive(Clone, ValueEnum)] -pub(crate) enum ConfigRevision { - #[clap(name = "20240701")] - V20240701, -} - #[derive(thiserror::Error, Debug)] pub(crate) enum Error { #[error(transparent)] diff --git a/src/command/config/migrate.rs b/src/command/config/migrate.rs index 90ce7ae..273a1cf 100644 --- a/src/command/config/migrate.rs +++ b/src/command/config/migrate.rs @@ -2,7 +2,7 @@ mod v20240701; -use super::ConfigRevision; +use crate::config::Revision; #[derive(thiserror::Error, Debug)] pub(crate) enum MigrationError { @@ -10,9 +10,9 @@ pub(crate) enum MigrationError { V20240701(#[from] v20240701::Error), } -pub(super) async fn run(revision: ConfigRevision) -> Result<(), MigrationError> { +pub(super) async fn run(revision: Revision) -> Result<(), MigrationError> { match revision { - ConfigRevision::V20240701 => v20240701::run().await?, + Revision::V20240701 => v20240701::run().await?, } Ok(()) diff --git a/src/command/config/migrate/v20240701.rs b/src/command/config/migrate/v20240701.rs index e536051..e501fd1 100644 --- a/src/command/config/migrate/v20240701.rs +++ b/src/command/config/migrate/v20240701.rs @@ -1,7 +1,7 @@ //! `config migrate 20240701` subcommand //! -use crate::config::{client, server}; +use crate::config::{client, server, Revision}; use color_print::cprintln; use sqlx::{postgres::PgConnectOptions, ConnectOptions}; use std::{ @@ -272,6 +272,7 @@ fn create_new_server_config( }; let mut server_config = server::Config { + config_revision: Revision::V20240701, info: Some(server::Info { name: meta.name.to_owned(), description: meta.description.to_owned(), @@ -392,6 +393,7 @@ fn create_new_server_config( fn create_new_client_config(meta: Meta) -> Result { let mut config = client::Config { + config_revision: Revision::V20240701, theme: None, image: None, pinned_links: None, diff --git a/src/config/client.rs b/src/config/client.rs index 863e6d2..23f98f7 100644 --- a/src/config/client.rs +++ b/src/config/client.rs @@ -5,11 +5,13 @@ // Optional values are handled in the main Firefish program, and this tool // does not take care of it. +use super::Revision; use serde::{Deserialize, Serialize}; use validator::{Validate, ValidationError}; #[derive(Deserialize, Serialize, Validate, Debug)] pub struct Config { + pub config_revision: Revision, #[validate(nested)] pub theme: Option, #[validate(nested)] diff --git a/src/config/mod.rs b/src/config/mod.rs index c07f47e..d59200f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,2 +1,14 @@ pub mod client; pub mod server; + +use clap::ValueEnum; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize, Clone, ValueEnum, Debug)] +pub enum Revision { + #[clap(name = "20240701")] + #[serde(rename = "20240701")] + V20240701, +} + +pub const LATEST_REVISION: Revision = Revision::V20240701; diff --git a/src/config/server.rs b/src/config/server.rs index f6f1eca..b4b4d59 100644 --- a/src/config/server.rs +++ b/src/config/server.rs @@ -5,11 +5,13 @@ // Optional values are handled in the main Firefish program, and this tool // does not take care of it. +use super::Revision; use serde::{Deserialize, Serialize}; use validator::Validate; #[derive(Deserialize, Serialize, Validate, Debug)] pub struct Config { + pub config_revision: Revision, #[validate(nested)] pub info: Option, #[validate(nested)]