Skip to main content

wekan_cli/commands/
boards.rs

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