1mod config;
2mod migration;
3mod theme;
4mod utility;
5
6pub use config::*;
7pub use migration::*;
8
9use anyhow::Result;
10use clap::Parser;
11use toasty::Db;
12
13pub struct ToastyCli {
15 db: Db,
16 config: Config,
17}
18
19impl ToastyCli {
20 pub fn new(db: Db) -> Self {
22 Self {
23 db,
24 config: Config::default(),
25 }
26 }
27
28 pub fn with_config(db: Db, config: Config) -> Self {
30 Self { db, config }
31 }
32
33 pub fn config(&self) -> &Config {
35 &self.config
36 }
37
38 pub async fn parse_and_run(&self) -> Result<()> {
40 let cli = Cli::parse();
41 self.run(cli).await
42 }
43
44 pub async fn parse_from<I, T>(&self, args: I) -> Result<()>
46 where
47 I: IntoIterator<Item = T>,
48 T: Into<std::ffi::OsString> + Clone,
49 {
50 let cli = Cli::parse_from(args);
51 self.run(cli).await
52 }
53
54 async fn run(&self, cli: Cli) -> Result<()> {
55 match cli.command {
56 Command::Migration(cmd) => cmd.run(&self.db, &self.config).await,
57 }
58 }
59}
60
61#[derive(Parser, Debug)]
62#[command(name = "toasty")]
63#[command(about = "Toasty CLI - Database migration and management tool")]
64#[command(version)]
65struct Cli {
66 #[command(subcommand)]
67 command: Command,
68}
69
70#[derive(Parser, Debug)]
71enum Command {
72 Migration(migration::MigrationCommand),
74}