1mod cargo;
12mod config;
13mod extract;
14mod flavor;
15mod load_cdylib;
16mod migrate;
17mod project;
18mod theme;
19mod utility;
20
21pub use cargo::Features;
22pub use config::Config;
23pub use flavor::Flavor;
24pub use migrate::{MigrationConfig, MigrationPrefixStyle};
25pub use project::Project;
26
27use anyhow::{Context, Result};
28use clap::Parser;
29
30pub fn run() -> Result<()> {
32 run_parsed(Cli::parse())
33}
34
35pub fn run_from<I, T>(args: I) -> Result<()>
38where
39 I: IntoIterator<Item = T>,
40 T: Into<std::ffi::OsString> + Clone,
41{
42 run_parsed(Cli::parse_from(args))
43}
44
45fn run_parsed(cli: Cli) -> Result<()> {
46 match cli.command {
47 Command::LoadCdylib(cmd) => cmd.run(),
50 Command::Migrate(cmd) => {
51 let project = Project::locate(cli.package.as_deref(), cli.features)?;
52 runtime()?.block_on(cmd.run(&project))
53 }
54 }
55}
56
57fn runtime() -> Result<tokio::runtime::Runtime> {
60 tokio::runtime::Builder::new_multi_thread()
61 .enable_all()
62 .build()
63 .context("failed to start the async runtime")
64}
65
66#[derive(Parser, Debug)]
67#[command(name = "toasty")]
68#[command(about = "Toasty schema management and migrations")]
69#[command(version)]
70struct Cli {
71 #[arg(short, long, global = true, value_name = "PKG")]
73 package: Option<String>,
74
75 #[command(flatten)]
76 features: Features,
77
78 #[command(subcommand)]
79 command: Command,
80}
81
82#[derive(Parser, Debug)]
83enum Command {
84 Migrate(migrate::MigrateCommand),
86
87 #[command(name = "__load-cdylib", hide = true)]
90 LoadCdylib(load_cdylib::LoadCdylibCommand),
91}