Skip to main content

wekan_cli/commands/
boards.rs

1mod count;
2mod create;
3mod delete;
4mod get;
5mod list;
6mod members;
7mod rename;
8
9#[cfg(test)]
10mod tests;
11
12use clap::{Args, Subcommand};
13
14use crate::{
15    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
16    error::AppError, input::ConfirmationProvider,
17};
18
19#[derive(Debug, Args)]
20pub struct BoardArgs {
21    #[command(subcommand)]
22    pub command: BoardCommand,
23}
24
25#[derive(Debug, Subcommand)]
26pub enum BoardCommand {
27    /// List, add, remove, or change board members.
28    Member(members::MemberArgs),
29    /// List active boards for the authenticated user, or all public boards.
30    List(list::ListArgs),
31
32    /// Count all private and public boards on the server.
33    Count(count::CountArgs),
34
35    /// Show a board by ID.
36    Get(get::GetArgs),
37
38    /// Create a board and its default swimlane.
39    Create(create::CreateArgs),
40
41    /// Rename a board.
42    Rename(rename::RenameArgs),
43
44    /// Permanently delete a board and all of its contents.
45    Delete(delete::DeleteArgs),
46}
47
48pub(crate) async fn dispatch(
49    command: BoardCommand,
50    client_factory: &WekanClientFactory,
51    credential_store: &dyn CredentialStore,
52    confirmation: &dyn ConfirmationProvider,
53) -> Result<CommandSuccess, AppError> {
54    match command {
55        BoardCommand::Member(args) => {
56            members::dispatch(args.command, client_factory, credential_store).await
57        }
58        BoardCommand::List(args) => list::execute(args, client_factory, credential_store).await,
59        BoardCommand::Count(args) => count::execute(args, client_factory, credential_store).await,
60        BoardCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
61        BoardCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
62        BoardCommand::Rename(args) => rename::execute(args, client_factory, credential_store).await,
63        BoardCommand::Delete(args) => {
64            delete::execute(args, client_factory, credential_store, confirmation).await
65        }
66    }
67}
68
69fn non_empty(value: &str) -> Result<String, String> {
70    if value.is_empty() {
71        Err("value must not be empty".to_owned())
72    } else {
73        Ok(value.to_owned())
74    }
75}
76
77fn trimmed_non_empty(value: &str) -> Result<String, String> {
78    let value = value.trim();
79    if value.is_empty() {
80        Err("value must not be empty or whitespace".to_owned())
81    } else {
82        Ok(value.to_owned())
83    }
84}