pub(crate) mod commands;
pub(crate) mod config;
pub(crate) mod constants;
pub(crate) mod errors;
use anyhow::Result;
use clap::{Parser, Subcommand};
use commands::config::{ConfigCommand, ConfigCommandParser};
use commands::entity::{EntityCommand, EntityCommandParser};
use commands::project::{ProjectCommand, ProjectCommandParser};
use std::fs;
use std::path::PathBuf;
#[derive(Subcommand)]
enum CliCommand {
Project(ProjectCommandParser),
Entity(EntityCommandParser),
Config(ConfigCommandParser),
#[clap(hide = true)]
PrintAllHelp {
#[arg(short, long)]
out_path: PathBuf,
},
}
#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(next_line_help = true)]
struct Cli {
#[command(subcommand)]
command: CliCommand,
}
pub fn run() -> Result<()> {
let cli = Cli::parse();
match cli.command {
CliCommand::Project(project) => match project.command {
ProjectCommand::Create(project_create) => project_create.run(),
},
CliCommand::Entity(entity) => match entity.command {
EntityCommand::Create(entity_create) => entity_create.run(),
},
CliCommand::Config(config) => match config.command {
ConfigCommand::Create(config_create) => config_create.run(),
},
CliCommand::PrintAllHelp { out_path } => {
let markdown_str = clap_markdown::help_markdown::<Cli>();
fs::write(out_path, markdown_str)?;
Ok(())
}
}
}