mod copy;
mod count;
mod create;
mod delete;
mod get;
mod labels;
mod list;
mod members;
mod rename;
#[cfg(test)]
mod tests;
use clap::{Args, Subcommand};
use crate::{
client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
error::AppError, input::ConfirmationProvider,
};
#[derive(Debug, Args)]
pub struct BoardArgs {
#[command(subcommand)]
pub command: BoardCommand,
}
#[derive(Debug, Subcommand)]
pub enum BoardCommand {
Copy(copy::CopyArgs),
Label(labels::LabelArgs),
Member(members::MemberArgs),
List(list::ListArgs),
Count(count::CountArgs),
Get(get::GetArgs),
Create(create::CreateArgs),
Rename(rename::RenameArgs),
Delete(delete::DeleteArgs),
}
pub(crate) async fn dispatch(
command: BoardCommand,
client_factory: &WekanClientFactory,
credential_store: &dyn CredentialStore,
confirmation: &dyn ConfirmationProvider,
) -> Result<CommandSuccess, AppError> {
match command {
BoardCommand::Copy(args) => copy::execute(args, client_factory, credential_store).await,
BoardCommand::Label(args) => {
labels::dispatch(args.command, client_factory, credential_store).await
}
BoardCommand::Member(args) => {
members::dispatch(args.command, client_factory, credential_store).await
}
BoardCommand::List(args) => list::execute(args, client_factory, credential_store).await,
BoardCommand::Count(args) => count::execute(args, client_factory, credential_store).await,
BoardCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
BoardCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
BoardCommand::Rename(args) => rename::execute(args, client_factory, credential_store).await,
BoardCommand::Delete(args) => {
delete::execute(args, client_factory, credential_store, confirmation).await
}
}
}
fn non_empty(value: &str) -> Result<String, String> {
if value.is_empty() {
Err("value must not be empty".to_owned())
} else {
Ok(value.to_owned())
}
}
fn trimmed_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())
}
}