use std::path::Path;
use std::process::ExitCode;
use clap::{Args, Subcommand};
use crate::contexts::config::application::ConfigRepository;
pub mod edit;
pub mod update;
#[derive(Args)]
pub struct ConfigArgs {
#[command(subcommand)]
pub subcommand: ConfigCommand,
}
#[derive(Subcommand)]
pub enum ConfigCommand {
Edit,
Update,
}
pub fn run(
args: &ConfigArgs,
repo: &impl ConfigRepository,
config_path: Option<&Path>,
) -> ExitCode {
match args.subcommand {
ConfigCommand::Edit => {
let Some(path) = config_path else {
eprintln!(
"failed to edit config: could not determine config path (HOME or XDG_CONFIG_HOME required)"
);
return ExitCode::FAILURE;
};
if let Err(e) = edit::run(path) {
eprintln!("failed to edit config: {e}");
return ExitCode::FAILURE;
}
ExitCode::SUCCESS
}
ConfigCommand::Update => {
if let Err(e) = update::run(repo) {
eprintln!("failed to update config: {e}");
return ExitCode::FAILURE;
}
ExitCode::SUCCESS
}
}
}