mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 07:11:24 +01:00
wip: db convert command
This commit is contained in:
parent
b3d9cd5e9c
commit
0e3e5c10bf
5 changed files with 46 additions and 2 deletions
34
src/cli.rs
34
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(())
|
||||
}
|
||||
|
|
|
|||
1
src/cli/db.rs
Normal file
1
src/cli/db.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub(crate) mod convert;
|
||||
6
src/cli/db/convert.rs
Normal file
6
src/cli/db/convert.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use crate::{cli::DbConvert, error};
|
||||
|
||||
pub(crate) async fn run(args: DbConvert) -> Result<(), error::DbConvert> {
|
||||
println!("hello world");
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -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<dyn std::error::Error>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue