use clap::{Args, Parser, Subcommand};
use enum_variant_type::EnumVariantType;
use evt_trait_object::Variants;
use std::fmt::Debug;
use crate::commands::create::CreateCommands;
use crate::commands::db::DbCommands;
use crate::commands::manage::ManageCommands;
#[derive(Debug, Parser)]
#[command(
name = "sbp",
version,
styles = supercli::clap::create_minimal_help_styles()
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand, EnumVariantType, Variants)]
#[variants_trait(CliSubcommand)]
pub enum Commands {
#[evt(derive(Debug, Args))]
Completions {
#[arg(value_enum)]
shell: clap_complete_command::Shell,
#[arg(short, long)]
never_write: bool,
},
#[evt(derive(Debug))]
#[command(subcommand)]
Create(CreateCommands),
#[evt(derive(Debug))]
#[command(subcommand)]
Manage(ManageCommands),
#[evt(derive(Debug, Args))]
StopAny {},
#[evt(derive(Debug, Args))]
Upgrade {},
#[evt(derive(Debug, Args))]
Watch {
#[arg()]
directory: String,
#[arg(short = 'I', long)]
immediate: bool,
},
#[evt(derive(Debug))]
#[command(subcommand)]
Db(DbCommands),
}
#[async_trait::async_trait]
pub(crate) trait CliSubcommand: Debug + Send {
#[cfg(debug_assertions)]
async fn run(self: Box<Self>) -> anyhow::Result<()> {
println!("Running command: {:#?}", self);
Ok(())
}
#[cfg(not(debug_assertions))]
async fn run(self: Box<Self>) -> anyhow::Result<()>;
}