wip: db convert command

This commit is contained in:
Charles Hall 2024-09-26 20:43:58 -07:00
parent b3d9cd5e9c
commit 0e3e5c10bf
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
5 changed files with 46 additions and 2 deletions

View file

@ -7,8 +7,9 @@ use std::path::PathBuf;
use clap::{Parser, Subcommand};
use crate::error;
use crate::{config::DatabaseBackend, error};
mod db;
mod serve;
/// Command line arguments
@ -26,6 +27,10 @@ pub(crate) struct Args {
pub(crate) enum Command {
/// Run the server.
Serve(ServeArgs),
/// Database utilities
#[clap(subcommand)]
Db(DbCommand),
}
/// Wrapper for the `--config` arg.
@ -57,10 +62,37 @@ pub(crate) struct ServeArgs {
pub(crate) config: ConfigArg,
}
#[derive(Subcommand)]
pub(crate) enum DbCommand {
/// Convert between database backends
///
/// Once this command successfully completes, copy or move the `media`
/// directory from `IN_PATH` to `OUT_PATH` to complete the migration.
Convert(DbConvert),
}
#[derive(clap::Args)]
pub(crate) struct DbConvert {
/// The backend to convert from
in_backend: DatabaseBackend,
/// The backend to convert to
out_backend: DatabaseBackend,
/// Path to the database to read
in_path: PathBuf,
/// Path to write the new database
out_path: PathBuf,
}
impl Args {
pub(crate) async fn run(self) -> Result<(), error::Main> {
match self.command {
Command::Serve(args) => serve::run(args).await?,
Command::Db(DbCommand::Convert(args)) => {
db::convert::run(args).await?
}
}
Ok(())
}