Skip to main content

wekan_cli/commands/
comments.rs

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