#![warn(missing_docs)]
mod config;
mod migration;
mod theme;
mod utility;
pub use config::Config;
pub use migration::{
ApplyCommand, DropCommand, GenerateCommand, MigrationCommand, MigrationConfig,
MigrationPrefixStyle, ResetCommand, SnapshotCommand,
};
use anyhow::Result;
use clap::Parser;
use toasty::Db;
pub struct ToastyCli {
db: Db,
config: Config,
}
impl ToastyCli {
pub fn new(db: Db) -> Self {
Self {
db,
config: Config::default(),
}
}
pub fn with_config(db: Db, config: Config) -> Self {
Self { db, config }
}
pub fn config(&self) -> &Config {
&self.config
}
pub async fn parse_and_run(&self) -> Result<()> {
let cli = Cli::parse();
self.run(cli).await
}
pub async fn parse_from<I, T>(&self, args: I) -> Result<()>
where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
let cli = Cli::parse_from(args);
self.run(cli).await
}
async fn run(&self, cli: Cli) -> Result<()> {
match cli.command {
Command::Migration(cmd) => cmd.run(&self.db, &self.config).await,
}
}
}
#[derive(Parser, Debug)]
#[command(name = "toasty")]
#[command(about = "Toasty CLI - Database migration and management tool")]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Parser, Debug)]
enum Command {
Migration(migration::MigrationCommand),
}