use std::pin::Pin; use std::{future::Future, process::exit}; use clap::{ArgMatches, Command}; pub mod db_migrate_and_generate; pub struct CliCommand { pub command: Command, pub action: fn(&clap::ArgMatches) -> Pin + Send>>, } static CLI_COMMANDS: once_cell::sync::Lazy< [CliCommand; 1 /* Update this count when adding new commands */], > = once_cell::sync::Lazy::new(|| { [ // Add new commands here db_migrate_and_generate::get_cli_command(), ] }); pub fn get_command() -> Command { let mut c = Command::new("cmd"); for cmd in CLI_COMMANDS.iter() { c = c.subcommand(cmd.command.clone()); } c } pub fn execute(matches: &ArgMatches, help_msg: &str) -> Pin + Send>> { if let Some((subcommand_name, subcommand_matches)) = matches.subcommand() { for cmd in CLI_COMMANDS.iter() { if cmd.command.get_name() == subcommand_name { return (cmd.action)(subcommand_matches); } } } eprintln!("Error: No valid subcommand provided."); eprintln!("{}", help_msg); exit(1); }