Skip to main content

hitomi/cli/
mod.rs

1use crate::cli::config::CliConfig;
2use crate::cli::profile::CliProfile;
3use crate::cli::run::RunCmds;
4use crate::db;
5use crate::profiles::manager::ProfileManager;
6use anyhow::Result;
7use clap::{Parser, Subcommand};
8use log::Level;
9
10mod config;
11mod profile;
12mod run;
13
14#[derive(PartialEq, Parser)]
15#[command(version, about, long_about = None)]
16#[command(propagate_version = true)]
17pub struct Cli {
18    /// Use the database file at this location, if `DATABASE_URL` is not set
19    #[arg(long = "db")]
20    pub database_url: Option<String>,
21    /// Set logging level, e.g. Debug, Info, Error.
22    #[arg(long)]
23    pub log_level: Option<Level>,
24    /// hitomi commands
25    #[command(subcommand)]
26    pub commands: Commands,
27}
28
29#[derive(PartialEq, Subcommand)]
30pub enum Commands {
31    Run(RunCmds),
32    Profile(CliProfile),
33    Config(CliConfig),
34}
35
36pub async fn run_cli_command(cli: Cli) -> Result<()> {
37    db::initialize_pool(cli.database_url.as_deref()).await?;
38    match cli.commands {
39        Commands::Run(run) => {
40            run::execute_run_cmd(run).await?;
41        }
42        Commands::Profile(profile) => {
43            let manager = ProfileManager::new().await?;
44            profile::run_profile_command(profile, manager).await?
45        }
46        Commands::Config(cfg) => config::run_config_cmd(cfg).await?,
47    }
48
49    Ok(())
50}