wekan_cli/commands/
lists.rs1mod archive;
2mod create;
3mod delete;
4mod get;
5mod list;
6mod transfer;
7mod update;
8
9#[cfg(test)]
10mod tests;
11
12use clap::{Args, Subcommand};
13
14use crate::{
15 client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
16 error::AppError, input::ConfirmationProvider,
17};
18
19#[derive(Debug, Args)]
20pub struct ListArgs {
21 #[command(subcommand)]
22 pub command: ListCommand,
23}
24
25#[derive(Debug, Subcommand)]
26pub enum ListCommand {
27 Archive(archive::ArchiveArgs),
29 Restore(archive::ArchiveArgs),
31 Copy(transfer::TransferArgs),
33 Move(transfer::TransferArgs),
35 List(list::ListArgs),
37
38 Get(get::GetArgs),
40
41 Create(create::CreateArgs),
43
44 Update(update::UpdateArgs),
46
47 Delete(delete::DeleteArgs),
49}
50
51pub(crate) async fn dispatch(
52 command: ListCommand,
53 client_factory: &WekanClientFactory,
54 credential_store: &dyn CredentialStore,
55 confirmation: &dyn ConfirmationProvider,
56) -> Result<CommandSuccess, AppError> {
57 match command {
58 ListCommand::Archive(args) => {
59 archive::execute(args, true, client_factory, credential_store).await
60 }
61 ListCommand::Restore(args) => {
62 archive::execute(args, false, client_factory, credential_store).await
63 }
64 ListCommand::Copy(args) => {
65 transfer::execute(args, false, client_factory, credential_store).await
66 }
67 ListCommand::Move(args) => {
68 transfer::execute(args, true, client_factory, credential_store).await
69 }
70 ListCommand::List(args) => list::execute(args, client_factory, credential_store).await,
71 ListCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
72 ListCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
73 ListCommand::Update(args) => update::execute(args, client_factory, credential_store).await,
74 ListCommand::Delete(args) => {
75 delete::execute(args, client_factory, credential_store, confirmation).await
76 }
77 }
78}
79
80fn non_empty(value: &str) -> Result<String, String> {
81 trimmed_non_empty(value)
82}
83
84fn trimmed_non_empty(value: &str) -> Result<String, String> {
85 let value = value.trim();
86 if value.is_empty() {
87 Err("value must not be empty or whitespace".to_owned())
88 } else {
89 Ok(value.to_owned())
90 }
91}