use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "evenframe")]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[arg(short, long, global = true, env = "EVENFRAME_CONFIG")]
pub config: Option<PathBuf>,
#[arg(long, global = true, value_enum, default_value = "rust")]
pub source: SourceOfTruth,
#[arg(short, long, global = true)]
pub output: Option<PathBuf>,
#[arg(
short,
long,
global = true,
action = clap::ArgAction::Count,
conflicts_with = "quiet"
)]
pub verbose: u8,
#[arg(short, long, global = true)]
pub quiet: bool,
#[command(subcommand)]
pub command: Option<Commands>,
}
impl Cli {
pub fn log_filter(&self) -> &'static str {
if self.quiet {
"evenframe=error,evenframe_core=error"
} else {
match self.verbose {
0 => "evenframe=warn,evenframe_core=warn",
1 => "evenframe=info,evenframe_core=info",
2 => "evenframe=debug,evenframe_core=debug",
_ => "evenframe=trace,evenframe_core=trace",
}
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum SourceOfTruth {
Rust,
Flatbuffers,
Protobuf,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Typesync(TypesyncArgs),
Schemasync(SchemasyncArgs),
Generate(GenerateArgs),
Init(InitArgs),
Validate(ValidateArgs),
Info(InfoArgs),
TestPlugin(TestPluginArgs),
Cache(CacheArgs),
}
#[derive(Args, Debug, Clone)]
pub struct TypesyncArgs {
#[command(subcommand)]
pub command: Option<TypesyncCommands>,
#[arg(long)]
pub all: bool,
#[arg(long, value_delimiter = ',')]
pub formats: Option<Vec<TypeFormat>>,
#[arg(long, value_delimiter = ',')]
pub skip: Option<Vec<TypeFormat>>,
#[arg(long)]
pub per_file: bool,
}
#[derive(Subcommand, Debug, Clone)]
pub enum TypesyncCommands {
Arktype(ArktypeArgs),
Effect(EffectArgs),
Macroforge(MacroforgeArgs),
Flatbuffers(FlatbuffersArgs),
Protobuf(ProtobufArgs),
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, ValueEnum)]
pub enum TypeFormat {
Arktype,
Effect,
Macroforge,
Flatbuffers,
Protobuf,
}
#[derive(Args, Debug, Clone)]
pub struct ArktypeArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Args, Debug, Clone)]
pub struct EffectArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Args, Debug, Clone)]
pub struct MacroforgeArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
}
#[derive(Args, Debug, Clone)]
pub struct FlatbuffersArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(long)]
pub namespace: Option<String>,
}
#[derive(Args, Debug, Clone)]
pub struct ProtobufArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(long)]
pub package: Option<String>,
#[arg(long)]
pub import_validate: bool,
#[arg(long, conflicts_with = "import_validate")]
pub no_import_validate: bool,
}
#[derive(Args, Debug, Clone)]
pub struct SchemasyncArgs {
#[command(subcommand)]
pub command: Option<SchemasyncCommands>,
#[arg(long, env = "SURREALDB_URL")]
pub url: Option<String>,
#[arg(long, env = "SURREALDB_NS")]
pub namespace: Option<String>,
#[arg(long, env = "SURREALDB_DB")]
pub database: Option<String>,
#[arg(long)]
pub no_mocks: bool,
#[arg(long)]
pub full_refresh: bool,
}
#[derive(Subcommand, Debug, Clone)]
pub enum SchemasyncCommands {
Diff(DiffArgs),
Apply(ApplyArgs),
Mock(MockArgs),
}
#[derive(Args, Debug, Clone)]
pub struct DiffArgs {
#[arg(long, value_enum, default_value = "pretty")]
pub format: DiffFormat,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum DiffFormat {
Pretty,
Json,
Plain,
}
#[derive(Args, Debug, Clone)]
pub struct ApplyArgs {
#[arg(short = 'y', long)]
pub yes: bool,
#[arg(long)]
pub dry_run: bool,
}
#[derive(Args, Debug, Clone)]
pub struct MockArgs {
#[arg(long)]
pub count: Option<usize>,
#[arg(long, value_delimiter = ',')]
pub tables: Option<Vec<String>>,
}
#[derive(Args, Debug, Clone)]
pub struct GenerateArgs {
#[arg(long)]
pub skip_typesync: bool,
#[arg(long)]
pub skip_schemasync: bool,
#[arg(long)]
pub no_mocks: bool,
#[arg(short, long)]
pub watch: bool,
}
#[derive(Args, Debug, Clone)]
pub struct InitArgs {
#[arg(short, long)]
pub force: bool,
#[arg(long, value_enum, default_value = "surrealdb")]
pub provider: DatabaseProvider,
#[arg(long)]
pub minimal: bool,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum DatabaseProvider {
Surrealdb,
Postgres,
Mysql,
Sqlite,
}
#[derive(Args, Debug, Clone)]
pub struct ValidateArgs {
#[arg(long)]
pub config_only: bool,
#[arg(long)]
pub types_only: bool,
#[arg(long)]
pub check_db: bool,
}
#[derive(Args, Debug, Clone)]
pub struct InfoArgs {
#[arg(long)]
pub types: bool,
#[arg(long)]
pub config: bool,
#[arg(long)]
pub schema: bool,
#[arg(long, value_enum, default_value = "pretty")]
pub format: InfoFormat,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum InfoFormat {
Pretty,
Json,
Yaml,
}
#[derive(Args, Debug, Clone)]
pub struct TestPluginArgs {
#[arg(long)]
pub type_name: Option<String>,
#[arg(long, default_value = "true")]
pub changed_only: bool,
}
#[derive(Args, Debug, Clone)]
pub struct CacheArgs {
#[command(subcommand)]
pub command: CacheCommands,
}
#[derive(Subcommand, Debug, Clone)]
pub enum CacheCommands {
Status,
Warm,
Clear,
}