wekan-cli 2.0.0

Agent-first, human-friendly command-line client for Wekan
Documentation
mod create;
mod delete;
mod get;
mod list;
mod update;

#[cfg(test)]
mod tests;

use clap::{Args, Subcommand};

use crate::{
    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
    error::AppError, input::ConfirmationProvider,
};

#[derive(Debug, Args)]
pub struct CommentArgs {
    #[command(subcommand)]
    pub command: CommentCommand,
}

#[derive(Debug, Subcommand)]
pub enum CommentCommand {
    /// List comments on a card.
    List(list::ListArgs),

    /// Show one card comment.
    Get(get::GetArgs),

    /// Create a comment on a card.
    Create(create::CreateArgs),

    /// Replace the text of a card comment.
    Update(update::UpdateArgs),

    /// Permanently delete a card comment.
    Delete(delete::DeleteArgs),
}

pub(crate) async fn dispatch(
    command: CommentCommand,
    client_factory: &WekanClientFactory,
    credential_store: &dyn CredentialStore,
    confirmation: &dyn ConfirmationProvider,
) -> Result<CommandSuccess, AppError> {
    match command {
        CommentCommand::Update(args) => {
            update::execute(args, client_factory, credential_store).await
        }
        CommentCommand::List(args) => list::execute(args, client_factory, credential_store).await,
        CommentCommand::Get(args) => get::execute(args, client_factory, credential_store).await,
        CommentCommand::Create(args) => {
            create::execute(args, client_factory, credential_store).await
        }
        CommentCommand::Delete(args) => {
            delete::execute(args, client_factory, credential_store, confirmation).await
        }
    }
}

fn non_empty(value: &str) -> Result<String, String> {
    let value = value.trim();
    if value.is_empty() {
        Err("value must not be empty or whitespace".to_owned())
    } else {
        Ok(value.to_owned())
    }
}