mod commands;
mod config;
pub mod args;
pub mod global;
pub mod handlers;
use base_d::DictionaryRegistry;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "base-d")]
#[command(version)]
#[command(about = "Universal multi-dictionary encoder supporting RFC standards, emoji, ancient scripts, and numerous custom dictionaries", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[command(flatten)]
global: global::GlobalArgs,
}
#[derive(Subcommand)]
enum Commands {
#[command(visible_alias = "e")]
Encode(args::EncodeArgs),
#[command(visible_alias = "d")]
Decode(args::DecodeArgs),
Detect(args::DetectArgs),
Hash(args::HashArgs),
Schema(args::SchemaArgs),
Stele(args::SteleArgs),
Config {
#[command(subcommand)]
action: args::ConfigAction,
},
Neo(args::NeoArgs),
}
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
let config = DictionaryRegistry::load_with_overrides()?;
match cli.command {
Commands::Encode(args) => handlers::encode::handle(args, &cli.global, &config),
Commands::Decode(args) => handlers::decode::handle(args, &cli.global, &config),
Commands::Detect(args) => handlers::detect::handle(args, &cli.global, &config),
Commands::Hash(args) => handlers::hash::handle(args, &cli.global, &config),
Commands::Schema(args) => handlers::schema::handle(args, &cli.global, &config),
Commands::Stele(args) => handlers::stele::handle(args, &cli.global, &config),
Commands::Config { action } => handlers::config::handle(action, &cli.global, &config),
Commands::Neo(args) => handlers::neo::handle(args, &cli.global, &config),
}
}