Skip to main content

wekan_cli/commands/
boards.rs

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