Skip to main content

wekan_cli/commands/
boards.rs

1mod 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    /// List attachment links using Wekan's legacy board projection.
37    Attachment(attachments::AttachmentArgs),
38    /// Import an export document into a new board.
39    Import(import::ImportArgs),
40    /// Import Trello JSON or ZIP into new boards using /import-trello.
41    ImportTrello(import_trello::ImportTrelloArgs),
42    /// Import a native ZIP archive into an existing board.
43    ImportZip(import_zip::ImportZipArgs),
44    /// Export a native artifact to a file or validated raw stdout.
45    Export(Box<export::ExportArgs>),
46    /// Read or update card display controls and aging thresholds.
47    CardSettings(card_settings::CardSettingsArgs),
48    /// List or request changes to email-domain sharing.
49    Domain(domains::DomainArgs),
50    /// Copy a board using Wekan's native copy operation.
51    Copy(copy::CopyArgs),
52    /// List or add reusable board labels.
53    Label(labels::LabelArgs),
54    /// List, add, remove, or change board members.
55    Member(members::MemberArgs),
56    /// List active boards for the authenticated user, or all public boards.
57    List(list::ListArgs),
58
59    /// Count all private and public boards on the server.
60    Count(count::CountArgs),
61
62    /// Show a board by ID.
63    Get(get::GetArgs),
64
65    /// Create a board and its default swimlane.
66    Create(create::CreateArgs),
67
68    /// Rename a board.
69    Rename(rename::RenameArgs),
70
71    /// Permanently delete a board and all of its contents.
72    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}