Skip to main content

wekan_cli/commands/
cards.rs

1mod create;
2mod delete;
3mod get;
4mod list;
5mod update;
6
7#[cfg(test)]
8mod tests;
9
10use clap::{Args, Subcommand};
11use time::{OffsetDateTime, format_description::well_known::Rfc3339};
12
13use crate::{
14    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
15    error::AppError, input::ConfirmationProvider,
16};
17
18#[derive(Debug, Args)]
19pub struct CardArgs {
20    #[command(subcommand)]
21    pub command: CardCommand,
22}
23
24#[derive(Debug, Subcommand)]
25pub enum CardCommand {
26    /// List the cards returned by Wekan for a board list.
27    List(list::ListArgs),
28
29    /// Show one card by board, list, and card ID.
30    Get(get::GetArgs),
31
32    /// Create a card in a board list.
33    Create(create::CreateArgs),
34
35    /// Update one or more editable card fields.
36    Update(update::UpdateArgs),
37
38    /// Permanently delete a card and its child resources.
39    Delete(delete::DeleteArgs),
40}
41
42pub(crate) async fn dispatch(
43    command: CardCommand,
44    client_factory: &WekanClientFactory,
45    credential_store: &dyn CredentialStore,
46    confirmation: &dyn ConfirmationProvider,
47) -> Result<CommandSuccess, AppError> {
48    match command {
49        CardCommand::List(args) => list::execute(args, client_factory, credential_store).await,
50        CardCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
51        CardCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
52        CardCommand::Update(args) => update::execute(args, client_factory, credential_store).await,
53        CardCommand::Delete(args) => {
54            delete::execute(args, client_factory, credential_store, confirmation).await
55        }
56    }
57}
58
59fn non_empty(value: &str) -> Result<String, String> {
60    trimmed_non_empty(value)
61}
62
63fn trimmed_non_empty(value: &str) -> Result<String, String> {
64    let value = value.trim();
65    if value.is_empty() {
66        Err("value must not be empty or whitespace".to_owned())
67    } else {
68        Ok(value.to_owned())
69    }
70}
71
72fn rfc3339(value: &str) -> Result<String, String> {
73    OffsetDateTime::parse(value, &Rfc3339)
74        .map(|_| value.to_owned())
75        .map_err(|_| "value must be an RFC3339 date-time".to_owned())
76}