Skip to main content

wekan_cli/commands/
rules.rs

1mod create;
2mod definition;
3mod delete;
4mod get;
5mod list;
6#[cfg(test)]
7mod tests;
8mod update;
9
10use crate::{
11    client::WekanClientFactory, command_result::CommandSuccess, credentials::CredentialStore,
12    error::AppError, input::ConfirmationProvider,
13};
14use clap::{Args, Subcommand};
15
16#[derive(Debug, Args)]
17pub struct RuleArgs {
18    #[command(subcommand)]
19    pub command: RuleCommand,
20}
21#[derive(Debug, Subcommand)]
22pub enum RuleCommand {
23    /// List a board's automation rules and embedded trigger/action fields.
24    List(list::ListArgs),
25    /// Show a board automation rule.
26    Get(get::GetArgs),
27    /// Create a rule from a typed camelCase JSON definition.
28    Create(create::CreateArgs),
29    /// Merge a sparse JSON definition into a rule.
30    Update(update::UpdateArgs),
31    /// Delete a rule and its trigger/action, with confirmation or --yes.
32    Delete(delete::DeleteArgs),
33}
34pub(crate) async fn dispatch(
35    command: RuleCommand,
36    factory: &WekanClientFactory,
37    store: &dyn CredentialStore,
38    confirmation: &dyn ConfirmationProvider,
39) -> Result<CommandSuccess, AppError> {
40    match command {
41        RuleCommand::List(args) => list::execute(args, factory, store).await,
42        RuleCommand::Get(args) => get::execute(args, factory, store).await,
43        RuleCommand::Create(args) => create::execute(args, factory, store).await,
44        RuleCommand::Update(args) => update::execute(args, factory, store).await,
45        RuleCommand::Delete(args) => delete::execute(args, factory, store, confirmation).await,
46    }
47}
48#[derive(Debug, Args)]
49struct Target {
50    /// Wekan rule ID.
51    #[arg(value_parser = identifier, help_heading = "Target")]
52    rule_id: String,
53    /// Wekan board ID.
54    #[arg(long = "board", value_parser = identifier, help_heading = "Target")]
55    board_id: String,
56}
57fn identifier(value: &str) -> Result<String, String> {
58    super::transfer::identifier(value)
59}