Skip to main content

singularity_cli/commands/
config.rs

1use anyhow::Result;
2use clap::Subcommand;
3
4#[derive(Subcommand)]
5pub enum ConfigCmd {
6    #[command(
7        name = "set-token",
8        about = "Save API bearer token to ~/.config/singularity/config.toml"
9    )]
10    SetToken {
11        #[arg(help = "API bearer token from Singularity app")]
12        token: String,
13    },
14    #[command(name = "set-timezone", about = "Save timezone (IANA format) to config")]
15    SetTimezone {
16        #[arg(help = "IANA timezone name (e.g. Europe/Kyiv, America/New_York)")]
17        timezone: String,
18    },
19}
20
21pub fn run(cmd: ConfigCmd) -> Result<()> {
22    match cmd {
23        ConfigCmd::SetToken { token } => crate::config::set_token(&token),
24        ConfigCmd::SetTimezone { timezone } => {
25            timezone
26                .parse::<chrono_tz::Tz>()
27                .map_err(|_| anyhow::anyhow!("invalid timezone: {}", timezone))?;
28            crate::config::set_timezone(&timezone)
29        }
30    }
31}