use clap::{Parser, Subcommand};
use tracing::info;
use super::{create_env_file::create_env_file, load_config, Errors, IEnvVars};
const ENV_EXAMPLE_FILE: &str = ".env.example";
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Create,
Check,
}
pub fn env_vars_cli<TConfig>()
where
TConfig: IEnvVars,
{
let cli = Cli::parse();
let value = cli.command;
let command = match value {
Commands::Create => command_create::<TConfig>(),
Commands::Check => command_check::<TConfig>(),
};
command.ok();
}
fn command_create<TConfig>() -> Result<(), Errors>
where
TConfig: IEnvVars,
{
info!("Создаем файл {}", ENV_EXAMPLE_FILE);
create_env_file::<TConfig>(ENV_EXAMPLE_FILE)?;
info!("Файл {} создан", ENV_EXAMPLE_FILE);
Ok(())
}
fn command_check<TConfig>() -> Result<(), Errors>
where
TConfig: IEnvVars,
{
info!("Пробуем загрузить файл .env");
let config = load_config::<TConfig>()?;
info!("Загружены настройки: {:#?}", config);
Ok(())
}