Skip to main content

wekan_cli/commands/
boards.rs

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