Skip to main content

wekan_cli/commands/
lists.rs

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