mod create;
mod delete;
mod get;
mod update;
use clap::{Args, Subcommand};
use crate::{
client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
error::AppError, input::ConfirmationProvider,
};
#[derive(Debug, Args)]
pub struct ChecklistItemArgs {
#[command(subcommand)]
pub command: ChecklistItemCommand,
}
#[derive(Debug, Subcommand)]
pub enum ChecklistItemCommand {
Get(get::GetArgs),
Create(create::CreateArgs),
Update(update::UpdateArgs),
Delete(delete::DeleteArgs),
}
pub(crate) async fn dispatch(
command: ChecklistItemCommand,
client_factory: &WekanClientFactory,
credential_store: &dyn CredentialStore,
confirmation: &dyn ConfirmationProvider,
) -> Result<CommandSuccess, AppError> {
match command {
ChecklistItemCommand::Update(args) => {
update::execute(args, client_factory, credential_store).await
}
ChecklistItemCommand::Get(args) => {
get::execute(args, client_factory, credential_store).await
}
ChecklistItemCommand::Create(args) => {
create::execute(args, client_factory, credential_store).await
}
ChecklistItemCommand::Delete(args) => {
delete::execute(args, client_factory, credential_store, confirmation).await
}
}
}
fn non_empty(value: &str) -> Result<String, String> {
let value = value.trim();
if value.is_empty() {
Err("value must not be empty or whitespace".to_owned())
} else {
Ok(value.to_owned())
}
}