Skip to main content

wekan_cli/commands/
boards.rs

1mod card_settings;
2mod copy;
3mod count;
4mod create;
5mod delete;
6mod domains;
7mod export;
8mod get;
9mod labels;
10mod list;
11mod members;
12mod rename;
13
14#[cfg(test)]
15mod tests;
16
17use clap::{Args, Subcommand};
18
19use crate::{
20    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
21    error::AppError, input::ConfirmationProvider,
22};
23
24#[derive(Debug, Args)]
25pub struct BoardArgs {
26    #[command(subcommand)]
27    pub command: BoardCommand,
28}
29
30#[derive(Debug, Subcommand)]
31pub enum BoardCommand {
32    /// Export a native artifact to a file or validated raw stdout.
33    Export(Box<export::ExportArgs>),
34    /// Read or update card display controls and aging thresholds.
35    CardSettings(card_settings::CardSettingsArgs),
36    /// List or request changes to email-domain sharing.
37    Domain(domains::DomainArgs),
38    /// Copy a board using Wekan's native copy operation.
39    Copy(copy::CopyArgs),
40    /// List or add reusable board labels.
41    Label(labels::LabelArgs),
42    /// List, add, remove, or change board members.
43    Member(members::MemberArgs),
44    /// List active boards for the authenticated user, or all public boards.
45    List(list::ListArgs),
46
47    /// Count all private and public boards on the server.
48    Count(count::CountArgs),
49
50    /// Show a board by ID.
51    Get(get::GetArgs),
52
53    /// Create a board and its default swimlane.
54    Create(create::CreateArgs),
55
56    /// Rename a board.
57    Rename(rename::RenameArgs),
58
59    /// Permanently delete a board and all of its contents.
60    Delete(delete::DeleteArgs),
61}
62
63pub(crate) async fn dispatch(
64    command: BoardCommand,
65    client_factory: &WekanClientFactory,
66    credential_store: &dyn CredentialStore,
67    confirmation: &dyn ConfirmationProvider,
68) -> Result<CommandSuccess, AppError> {
69    match command {
70        BoardCommand::Export(args) => {
71            export::execute(*args, client_factory, credential_store).await
72        }
73        BoardCommand::CardSettings(args) => {
74            card_settings::dispatch(args.command, client_factory, credential_store).await
75        }
76        BoardCommand::Domain(args) => {
77            domains::dispatch(args.command, client_factory, credential_store).await
78        }
79        BoardCommand::Copy(args) => copy::execute(args, client_factory, credential_store).await,
80        BoardCommand::Label(args) => {
81            labels::dispatch(args.command, client_factory, credential_store).await
82        }
83        BoardCommand::Member(args) => {
84            members::dispatch(args.command, client_factory, credential_store).await
85        }
86        BoardCommand::List(args) => list::execute(args, client_factory, credential_store).await,
87        BoardCommand::Count(args) => count::execute(args, client_factory, credential_store).await,
88        BoardCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
89        BoardCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
90        BoardCommand::Rename(args) => rename::execute(args, client_factory, credential_store).await,
91        BoardCommand::Delete(args) => {
92            delete::execute(args, client_factory, credential_store, confirmation).await
93        }
94    }
95}
96
97fn non_empty(value: &str) -> Result<String, String> {
98    if value.is_empty() {
99        Err("value must not be empty".to_owned())
100    } else {
101        Ok(value.to_owned())
102    }
103}
104
105fn trimmed_non_empty(value: &str) -> Result<String, String> {
106    let value = value.trim();
107    if value.is_empty() {
108        Err("value must not be empty or whitespace".to_owned())
109    } else {
110        Ok(value.to_owned())
111    }
112}