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, config::MissingProfileResolution,
14    credentials::CredentialStore, 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
41impl ListCommand {
42    pub(crate) const fn missing_profile_resolution(&self) -> MissingProfileResolution {
43        MissingProfileResolution::Reject
44    }
45}
46
47pub(crate) async fn dispatch(
48    command: ListCommand,
49    client_factory: &WekanClientFactory,
50    credential_store: &dyn CredentialStore,
51    confirmation: &dyn ConfirmationProvider,
52) -> Result<CommandSuccess, AppError> {
53    match command {
54        ListCommand::List(args) => list::execute(args, client_factory, credential_store).await,
55        ListCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
56        ListCommand::Create(args) => create::execute(args, client_factory, credential_store).await,
57        ListCommand::Update(args) => update::execute(args, client_factory, credential_store).await,
58        ListCommand::Delete(args) => {
59            delete::execute(args, client_factory, credential_store, confirmation).await
60        }
61    }
62}
63
64fn non_empty(value: &str) -> Result<String, String> {
65    trimmed_non_empty(value)
66}
67
68fn trimmed_non_empty(value: &str) -> Result<String, String> {
69    let value = value.trim();
70    if value.is_empty() {
71        Err("value must not be empty or whitespace".to_owned())
72    } else {
73        Ok(value.to_owned())
74    }
75}