mod attachments;
mod card_settings;
mod chart;
mod copy;
mod count;
mod create;
mod delete;
mod domains;
mod export;
mod export_all;
mod get;
mod import;
mod import_trello;
mod import_zip;
mod labels;
mod list;
mod members;
mod presentation;
mod rename;
#[cfg(test)]
mod tests;
use clap::{Args, Subcommand};
use crate::{
client::WekanClientFactory,
command_result::CommandSuccess,
credentials::{CredentialStore, SecretInputProvider},
error::AppError,
input::ConfirmationProvider,
};
#[derive(Debug, Args)]
pub struct BoardArgs {
#[command(subcommand)]
pub command: BoardCommand,
}
#[derive(Debug, Subcommand)]
pub enum BoardCommand {
ExportAll(Box<export_all::ExportAllArgs>),
Chart(chart::ChartArgs),
ViewSettings(presentation::ViewSettingsArgs),
CardFieldOrder(presentation::CardFieldOrderArgs),
Attachment(attachments::AttachmentArgs),
Import(import::ImportArgs),
ImportTrello(import_trello::ImportTrelloArgs),
ImportZip(import_zip::ImportZipArgs),
Export(Box<export::ExportArgs>),
CardSettings(card_settings::CardSettingsArgs),
Domain(domains::DomainArgs),
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,
secrets: &dyn SecretInputProvider,
confirmation: &dyn ConfirmationProvider,
) -> Result<CommandSuccess, AppError> {
match command {
BoardCommand::ExportAll(args) => {
export_all::execute(*args, client_factory, credential_store).await
}
BoardCommand::Chart(args) => {
chart::dispatch(args.command, client_factory, credential_store).await
}
BoardCommand::ViewSettings(args) => {
presentation::views(args.command, client_factory, credential_store).await
}
BoardCommand::CardFieldOrder(args) => {
presentation::order(args.command, client_factory, credential_store).await
}
BoardCommand::Attachment(args) => {
attachments::dispatch(args.command, client_factory, credential_store).await
}
BoardCommand::Import(args) => {
import::execute(args, client_factory, credential_store, secrets).await
}
BoardCommand::ImportTrello(args) => {
import_trello::execute(args, client_factory, credential_store).await
}
BoardCommand::ImportZip(args) => {
import_zip::execute(args, client_factory, credential_store).await
}
BoardCommand::Export(args) => {
export::execute(*args, client_factory, credential_store).await
}
BoardCommand::CardSettings(args) => {
card_settings::dispatch(args.command, client_factory, credential_store).await
}
BoardCommand::Domain(args) => {
domains::dispatch(args.command, client_factory, credential_store).await
}
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())
}
}