wekan_cli/commands/
comments.rs1mod 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, config::MissingProfileResolution,
13 credentials::CredentialStore, 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(list::ListArgs),
26
27 Get(get::GetArgs),
29
30 Create(create::CreateArgs),
32
33 Delete(delete::DeleteArgs),
35}
36
37impl CommentCommand {
38 pub(crate) const fn missing_profile_resolution(&self) -> MissingProfileResolution {
39 MissingProfileResolution::Reject
40 }
41}
42
43pub(crate) async fn dispatch(
44 command: CommentCommand,
45 client_factory: &WekanClientFactory,
46 credential_store: &dyn CredentialStore,
47 confirmation: &dyn ConfirmationProvider,
48) -> Result<CommandSuccess, AppError> {
49 match command {
50 CommentCommand::List(args) => list::execute(args, client_factory, credential_store).await,
51 CommentCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
52 CommentCommand::Create(args) => {
53 create::execute(args, client_factory, credential_store).await
54 }
55 CommentCommand::Delete(args) => {
56 delete::execute(args, client_factory, credential_store, confirmation).await
57 }
58 }
59}
60
61fn non_empty(value: &str) -> Result<String, String> {
62 let value = value.trim();
63 if value.is_empty() {
64 Err("value must not be empty or whitespace".to_owned())
65 } else {
66 Ok(value.to_owned())
67 }
68}