1use clap::{Parser, Subcommand};
4use tracing::info;
5
6use super::{create_env_file::create_env_file, load_config, Errors, IEnvVars};
7
8const ENV_EXAMPLE_FILE: &str = ".env.example";
9
10#[derive(Parser)]
12#[command(author, version, about, long_about = None)]
13pub struct Cli {
14 #[command(subcommand)]
15 pub command: Commands,
16}
17
18#[derive(Subcommand)]
20pub enum Commands {
21 Create,
23 Check,
25}
26
27pub fn env_vars_cli<TConfig>()
29where
30 TConfig: IEnvVars,
31{
32 let cli = Cli::parse();
33
34 let value = cli.command;
35 let command = match value {
36 Commands::Create => command_create::<TConfig>(),
37 Commands::Check => command_check::<TConfig>(),
38 };
39 command.ok();
40}
41
42fn command_create<TConfig>() -> Result<(), Errors>
43where
44 TConfig: IEnvVars,
45{
46 info!("Создаем файл {}", ENV_EXAMPLE_FILE);
47 create_env_file::<TConfig>(ENV_EXAMPLE_FILE)?;
48 info!("Файл {} создан", ENV_EXAMPLE_FILE);
49 Ok(())
50}
51
52fn command_check<TConfig>() -> Result<(), Errors>
53where
54 TConfig: IEnvVars,
55{
56 info!("Пробуем загрузить файл .env");
57 let config = load_config::<TConfig>()?;
58 info!("Загружены настройки: {:#?}", config);
59 Ok(())
60}