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, config::MissingProfileResolution,
15    credentials::CredentialStore, 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
45impl BoardCommand {
46    pub(crate) const fn missing_profile_resolution(&self) -> MissingProfileResolution {
47        MissingProfileResolution::Reject
48    }
49}
50
51pub(crate) async fn dispatch(
52    command: BoardCommand,
53    client_factory: &WekanClientFactory,
54    credential_store: &dyn CredentialStore,
55    confirmation: &dyn ConfirmationProvider,
56) -> Result<CommandSuccess, AppError> {
57    match command {
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}