Skip to main content

wekan_cli/commands/
checklists.rs

1mod create;
2mod delete;
3mod get;
4mod list;
5
6use clap::{Args, Subcommand};
7
8use crate::{
9    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
10    error::AppError, input::ConfirmationProvider,
11};
12
13#[derive(Debug, Args)]
14pub struct ChecklistArgs {
15    #[command(subcommand)]
16    pub command: ChecklistCommand,
17}
18
19#[derive(Debug, Subcommand)]
20pub enum ChecklistCommand {
21    /// List checklists on a card.
22    List(list::ListArgs),
23
24    /// Show one card checklist.
25    Get(get::GetArgs),
26
27    /// Create a checklist on a card.
28    Create(create::CreateArgs),
29
30    /// Permanently delete a card checklist.
31    Delete(delete::DeleteArgs),
32
33    /// Inspect and manage checklist items.
34    Item(super::checklist_items::ChecklistItemArgs),
35}
36
37pub(crate) async fn dispatch(
38    command: ChecklistCommand,
39    client_factory: &WekanClientFactory,
40    credential_store: &dyn CredentialStore,
41    confirmation: &dyn ConfirmationProvider,
42) -> Result<CommandSuccess, AppError> {
43    match command {
44        ChecklistCommand::List(args) => list::execute(args, client_factory, credential_store).await,
45        ChecklistCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
46        ChecklistCommand::Create(args) => {
47            create::execute(args, client_factory, credential_store).await
48        }
49        ChecklistCommand::Delete(args) => {
50            delete::execute(args, client_factory, credential_store, confirmation).await
51        }
52        ChecklistCommand::Item(args) => {
53            super::checklist_items::dispatch(
54                args.command,
55                client_factory,
56                credential_store,
57                confirmation,
58            )
59            .await
60        }
61    }
62}
63
64fn non_empty(value: &str) -> Result<String, String> {
65    let value = value.trim();
66    if value.is_empty() {
67        Err("value must not be empty or whitespace".to_owned())
68    } else {
69        Ok(value.to_owned())
70    }
71}
72
73#[cfg(test)]
74mod tests;