wekan_cli/commands/
boards.rs1mod attachments;
2mod card_settings;
3mod copy;
4mod count;
5mod create;
6mod delete;
7mod domains;
8mod export;
9mod get;
10mod import;
11mod import_trello;
12mod import_zip;
13mod labels;
14mod list;
15mod members;
16mod rename;
17
18#[cfg(test)]
19mod tests;
20
21use clap::{Args, Subcommand};
22
23use crate::{
24 client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
25 error::AppError, input::ConfirmationProvider,
26};
27
28#[derive(Debug, Args)]
29pub struct BoardArgs {
30 #[command(subcommand)]
31 pub command: BoardCommand,
32}
33
34#[derive(Debug, Subcommand)]
35pub enum BoardCommand {
36 Attachment(attachments::AttachmentArgs),
38 Import(import::ImportArgs),
40 ImportTrello(import_trello::ImportTrelloArgs),
42 ImportZip(import_zip::ImportZipArgs),
44 Export(Box<export::ExportArgs>),
46 CardSettings(card_settings::CardSettingsArgs),
48 Domain(domains::DomainArgs),
50 Copy(copy::CopyArgs),
52 Label(labels::LabelArgs),
54 Member(members::MemberArgs),
56 List(list::ListArgs),
58
59 Count(count::CountArgs),
61
62 Get(get::GetArgs),
64
65 Create(create::CreateArgs),
67
68 Rename(rename::RenameArgs),
70
71 Delete(delete::DeleteArgs),
73}
74
75pub(crate) async fn dispatch(
76 command: BoardCommand,
77 client_factory: &WekanClientFactory,
78 credential_store: &dyn CredentialStore,
79 confirmation: &dyn ConfirmationProvider,
80) -> Result<CommandSuccess, AppError> {
81 match command {
82 BoardCommand::Attachment(args) => {
83 attachments::dispatch(args.command, client_factory, credential_store).await
84 }
85 BoardCommand::Import(args) => import::execute(args, client_factory, credential_store).await,
86 BoardCommand::ImportTrello(args) => {
87 import_trello::execute(args, client_factory, credential_store).await
88 }
89 BoardCommand::ImportZip(args) => {
90 import_zip::execute(args, client_factory, credential_store).await
91 }
92 BoardCommand::Export(args) => {
93 export::execute(*args, client_factory, credential_store).await
94 }
95 BoardCommand::CardSettings(args) => {
96 card_settings::dispatch(args.command, client_factory, credential_store).await
97 }
98 BoardCommand::Domain(args) => {
99 domains::dispatch(args.command, client_factory, credential_store).await
100 }
101 BoardCommand::Copy(args) => copy::execute(args, client_factory, credential_store).await,
102 BoardCommand::Label(args) => {
103 labels::dispatch(args.command, client_factory, credential_store).await
104 }
105 BoardCommand::Member(args) => {
106 members::dispatch(args.command, client_factory, credential_store).await
107 }
108 BoardCommand::List(args) => list::execute(args, client_factory, credential_store).await,
109 BoardCommand::Count(args) => count::execute(args, client_factory, credential_store).await,
110 BoardCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
111 BoardCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
112 BoardCommand::Rename(args) => rename::execute(args, client_factory, credential_store).await,
113 BoardCommand::Delete(args) => {
114 delete::execute(args, client_factory, credential_store, confirmation).await
115 }
116 }
117}
118
119fn non_empty(value: &str) -> Result<String, String> {
120 if value.is_empty() {
121 Err("value must not be empty".to_owned())
122 } else {
123 Ok(value.to_owned())
124 }
125}
126
127fn trimmed_non_empty(value: &str) -> Result<String, String> {
128 let value = value.trim();
129 if value.is_empty() {
130 Err("value must not be empty or whitespace".to_owned())
131 } else {
132 Ok(value.to_owned())
133 }
134}