diff --git a/src/cli.rs b/src/cli.rs index c997ad67..c61fb72e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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(()) } diff --git a/src/cli/db.rs b/src/cli/db.rs new file mode 100644 index 00000000..02d63d4e --- /dev/null +++ b/src/cli/db.rs @@ -0,0 +1 @@ +pub(crate) mod convert; diff --git a/src/cli/db/convert.rs b/src/cli/db/convert.rs new file mode 100644 index 00000000..7af1e61c --- /dev/null +++ b/src/cli/db/convert.rs @@ -0,0 +1,6 @@ +use crate::{cli::DbConvert, error}; + +pub(crate) async fn run(args: DbConvert) -> Result<(), error::DbConvert> { + println!("hello world"); + Ok(()) +} diff --git a/src/config.rs b/src/config.rs index 0a5ed2d5..5625d1d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -216,7 +216,7 @@ impl Default for TurnConfig { } } -#[derive(Clone, Copy, Debug, Deserialize)] +#[derive(Clone, Copy, Debug, Deserialize, clap::ValueEnum)] #[serde(rename_all = "lowercase")] pub(crate) enum DatabaseBackend { #[cfg(feature = "rocksdb")] diff --git a/src/error.rs b/src/error.rs index 106484df..9bff6bd3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,6 +42,8 @@ impl fmt::Display for DisplayWithSources<'_> { pub(crate) enum Main { #[error(transparent)] ServeCommand(#[from] ServeCommand), + #[error(transparent)] + DbConvert(#[from] DbConvert), } /// Errors returned from the `serve` CLI subcommand. @@ -161,3 +163,6 @@ pub(crate) enum Serve { #[error("failed to run request listener on {1}")] Listen(#[source] std::io::Error, ListenConfig), } + +/// Errors converting between database backends +pub(crate) type DbConvert = Box;