add revision to the config file

This commit is contained in:
naskya 2024-06-21 03:41:48 +09:00
parent db8dfa6655
commit 6e908aebdb
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
6 changed files with 25 additions and 12 deletions

View file

@ -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)]

View file

@ -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(())

View file

@ -1,7 +1,7 @@
//! `config migrate 20240701` subcommand
//! <https://firefish.dev/firefish/firefish/-/issues/10947>
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<client::Config, Error> {
let mut config = client::Config {
config_revision: Revision::V20240701,
theme: None,
image: None,
pinned_links: None,

View file

@ -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<Theme>,
#[validate(nested)]

View file

@ -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;

View file

@ -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<Info>,
#[validate(nested)]