use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use migrate::commands;
#[derive(Parser)]
#[command(name = "migrate", version, about = "Generic file migration tool")]
struct Cli {
#[arg(short = 'r', long, default_value = ".")]
root: PathBuf,
#[arg(short = 'm', long, default_value = "migrations")]
migrations: PathBuf,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Status,
Up {
#[arg(long)]
dry_run: bool,
#[arg(long)]
baseline: bool,
#[arg(long)]
keep: bool,
},
Create {
name: Option<String>,
#[arg(short = 't', long, default_value = "bash")]
template: String,
#[arg(short = 'd', long)]
description: Option<String>,
#[arg(long)]
list_templates: bool,
},
Baseline {
version: String,
#[arg(short = 's', long)]
summary: Option<String>,
#[arg(long)]
dry_run: bool,
#[arg(long)]
keep: bool,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Status => {
commands::status::run(&cli.root, &cli.migrations)?;
}
Commands::Up {
dry_run,
baseline,
keep,
} => {
commands::up::run(&cli.root, &cli.migrations, dry_run, baseline, keep)?;
}
Commands::Create {
name,
template,
description,
list_templates,
} => {
commands::create::run(
&cli.root,
&cli.migrations,
name.as_deref(),
&template,
description.as_deref(),
list_templates,
)?;
}
Commands::Baseline {
version,
summary,
dry_run,
keep,
} => {
commands::baseline::run(
&cli.root,
&cli.migrations,
&version,
summary.as_deref(),
dry_run,
keep,
)?;
}
}
Ok(())
}