Skip to main content

wekan_cli/commands/
lists.rs

1mod 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 a list and its active cards.
28    Archive(archive::ArchiveArgs),
29    /// Restore an archived list through Wekan's native restore operation.
30    Restore(archive::ArchiveArgs),
31    /// Copy a list using Wekan's native transfer behavior.
32    Copy(transfer::TransferArgs),
33    /// Move or reposition a list; Wekan may retain the source or fail after partial changes.
34    Move(transfer::TransferArgs),
35    /// List the lists returned by Wekan for a board.
36    List(list::ListArgs),
37
38    /// Show one list by board and list ID.
39    Get(get::GetArgs),
40
41    /// Create a list on a board.
42    Create(create::CreateArgs),
43
44    /// Update one or more editable list fields.
45    Update(update::UpdateArgs),
46
47    /// Soft-delete a list and its live cards.
48    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}