2024-06-21 05:00:46 +09:00
|
|
|
//! `config update` subcommand
|
2024-06-20 08:17:13 +09:00
|
|
|
|
2024-06-20 02:42:33 +09:00
|
|
|
mod v20240701;
|
2024-06-20 02:07:34 +09:00
|
|
|
|
2024-06-21 04:36:44 +09:00
|
|
|
use crate::{
|
|
|
|
command::config::{next_revision, RevisionCheckError},
|
|
|
|
config::Revision,
|
|
|
|
};
|
2024-06-20 02:07:34 +09:00
|
|
|
|
|
|
|
#[derive(thiserror::Error, Debug)]
|
2024-06-21 05:00:46 +09:00
|
|
|
pub(crate) enum UpdateError {
|
2024-06-21 04:27:03 +09:00
|
|
|
#[error(transparent)]
|
2024-06-21 04:36:44 +09:00
|
|
|
UnknownRevision(#[from] RevisionCheckError),
|
2024-06-20 03:19:20 +09:00
|
|
|
#[error(transparent)]
|
|
|
|
V20240701(#[from] v20240701::Error),
|
2024-06-20 02:07:34 +09:00
|
|
|
}
|
|
|
|
|
2024-06-21 05:00:46 +09:00
|
|
|
async fn update_to_latest() -> Result<(), UpdateError> {
|
2024-06-21 04:27:03 +09:00
|
|
|
if next_revision()?.is_none() {
|
|
|
|
println!("Your config files are already up-to-date! (as of this fishctl release)");
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
while let Some(next_revision) = next_revision()? {
|
|
|
|
run_impl(next_revision).await?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-06-21 05:00:46 +09:00
|
|
|
async fn run_impl(revision: Revision) -> Result<(), UpdateError> {
|
2024-06-21 03:31:13 +09:00
|
|
|
match revision {
|
2024-06-21 03:41:48 +09:00
|
|
|
Revision::V20240701 => v20240701::run().await?,
|
2024-06-20 02:07:34 +09:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-06-21 04:27:03 +09:00
|
|
|
|
2024-06-21 05:00:46 +09:00
|
|
|
pub(super) async fn run(revision: Option<Revision>) -> Result<(), UpdateError> {
|
2024-06-21 04:27:03 +09:00
|
|
|
match revision {
|
|
|
|
Some(revision) => run_impl(revision).await,
|
|
|
|
None => update_to_latest().await,
|
|
|
|
}
|
|
|
|
}
|