wekan_cli/commands/
checklist_items.rs1mod create;
2mod delete;
3mod get;
4mod update;
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 ChecklistItemArgs {
15 #[command(subcommand)]
16 pub command: ChecklistItemCommand,
17}
18
19#[derive(Debug, Subcommand)]
20pub enum ChecklistItemCommand {
21 Get(get::GetArgs),
23
24 Create(create::CreateArgs),
26
27 Update(update::UpdateArgs),
29
30 Delete(delete::DeleteArgs),
32}
33
34pub(crate) async fn dispatch(
35 command: ChecklistItemCommand,
36 client_factory: &WekanClientFactory,
37 credential_store: &dyn CredentialStore,
38 confirmation: &dyn ConfirmationProvider,
39) -> Result<CommandSuccess, AppError> {
40 match command {
41 ChecklistItemCommand::Update(args) => {
42 update::execute(args, client_factory, credential_store).await
43 }
44 ChecklistItemCommand::Get(args) => {
45 get::execute(args, client_factory, credential_store).await
46 }
47 ChecklistItemCommand::Create(args) => {
48 create::execute(args, client_factory, credential_store).await
49 }
50 ChecklistItemCommand::Delete(args) => {
51 delete::execute(args, client_factory, credential_store, confirmation).await
52 }
53 }
54}
55
56fn non_empty(value: &str) -> Result<String, String> {
57 let value = value.trim();
58 if value.is_empty() {
59 Err("value must not be empty or whitespace".to_owned())
60 } else {
61 Ok(value.to_owned())
62 }
63}
64
65fn deadline(value: &str) -> Result<String, String> {
66 time::OffsetDateTime::parse(value, &time::format_description::well_known::Rfc3339)
67 .map(|_| value.to_owned())
68 .map_err(|_| "expected an RFC 3339 date-time with a timezone".to_owned())
69}