use crate::{
GlobalArgs, Subcommand,
util::{edit_and_validate, print_yaml},
};
use clap::Parser;
use slumber_config::Config;
use std::process::ExitCode;
#[derive(Clone, Debug, Parser)]
pub struct ConfigCommand {
#[clap(long)]
#[expect(rustdoc::bare_urls)]
edit: bool,
#[clap(long)]
path: bool,
}
impl Subcommand for ConfigCommand {
async fn execute(self, _global: GlobalArgs) -> anyhow::Result<ExitCode> {
if self.path {
let path = Config::path();
println!("{}", path.display());
Ok(ExitCode::SUCCESS)
} else if self.edit {
let config = Config::load().unwrap_or_default();
let path = Config::path();
edit_and_validate(&config, &path, Config::load)
} else {
let config = Config::load()?;
print_yaml(&config)?;
Ok(ExitCode::SUCCESS)
}
}
}