Skip to main content

wekan_cli/commands/
comments.rs

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