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)]
#[clap(verbatim_doc_comment)]
pub struct CollectionCommand {
#[clap(long)]
#[expect(rustdoc::bare_urls)]
edit: bool,
#[clap(long)]
path: bool,
}
impl Subcommand for CollectionCommand {
async fn execute(self, global: GlobalArgs) -> anyhow::Result<ExitCode> {
let collection_file = global.collection_file()?;
if self.path {
println!("{collection_file}");
Ok(ExitCode::SUCCESS)
} else if self.edit {
let config = Config::load()?;
edit_and_validate(&config, collection_file.path(), || {
collection_file.load()
})
} else {
let collection = collection_file.load()?;
print_yaml(&collection)?;
Ok(ExitCode::SUCCESS)
}
}
}