Skip to main content

wekan_cli/
commands.rs

1pub mod admin;
2pub mod api;
3pub mod attachments;
4pub mod auth;
5pub(crate) mod authenticated;
6pub mod boards;
7pub mod cards;
8pub mod checklist_items;
9pub mod checklists;
10pub(crate) mod client_error;
11pub mod comments;
12pub(crate) mod credential_ops;
13pub mod custom_field_items;
14pub mod custom_fields;
15pub mod dependencies;
16pub(crate) mod exports;
17pub(crate) mod imports;
18pub mod integrations;
19pub mod lists;
20pub mod profile;
21pub mod rules;
22pub mod skill;
23pub mod swimlanes;
24pub mod system;
25mod transfer;
26pub mod users;
27
28#[cfg(test)]
29mod tests;
30
31use clap::Subcommand;
32
33#[derive(Debug, Subcommand)]
34pub enum RootCommand {
35    /// Read agent guidance embedded in this CLI version.
36    Skill(skill::SkillArgs),
37    /// Inspect public Wekan system status.
38    System(system::SystemArgs),
39    /// Report domains and configure global settings, organizations, and teams.
40    Admin(Box<admin::AdminArgs>),
41    /// Inspect and manage board automation rules.
42    Rule(rules::RuleArgs),
43    /// Inspect and manage board integrations and webhook subscriptions.
44    Integration(integrations::IntegrationArgs),
45    /// Inspect and manage card dependency lines.
46    Dependency(dependencies::DependencyArgs),
47    /// Inspect, transfer and manage Wekan attachments.
48    Attachment(attachments::AttachmentArgs),
49    /// Send a low-level request to the selected Wekan server.
50    Api(api::ApiArgs),
51
52    /// Authenticate with a Wekan server.
53    Auth(auth::AuthArgs),
54
55    /// Manage named local Wekan server profiles.
56    Profile(profile::ProfileArgs),
57
58    /// Inspect and administer Wekan users.
59    User(users::UserArgs),
60
61    /// Inspect and manage Wekan boards.
62    Board(boards::BoardArgs),
63
64    /// Inspect and manage lists on Wekan boards.
65    List(lists::ListArgs),
66
67    /// Inspect and manage cards in Wekan board lists.
68    Card(Box<cards::CardArgs>),
69
70    /// Inspect and manage checklists on Wekan cards.
71    Checklist(checklists::ChecklistArgs),
72
73    /// Inspect and manage comments on Wekan cards.
74    Comment(comments::CommentArgs),
75
76    /// Inspect and manage custom-field definitions.
77    CustomField(custom_fields::CustomFieldArgs),
78
79    /// Inspect and manage swimlanes on Wekan boards.
80    Swimlane(swimlanes::SwimlaneArgs),
81}
82
83impl RootCommand {
84    pub fn supports_raw_output(&self) -> bool {
85        matches!(self, Self::Api(_))
86            || self.export_delivery().is_some_and(|d| d.is_stdout())
87            || matches!(self, Self::Attachment(args) if args.command.download_destination().is_some_and(|d| d.is_stdout()))
88    }
89
90    pub(crate) fn export_delivery(&self) -> Option<&exports::DeliveryArgs> {
91        match self {
92            Self::Board(a) => {
93                if let boards::BoardCommand::Export(e) = &a.command {
94                    Some(&e.delivery)
95                } else {
96                    None
97                }
98            }
99            Self::Card(a) => {
100                if let cards::CardCommand::Export(e) = &a.command {
101                    Some(&e.delivery)
102                } else {
103                    None
104                }
105            }
106            Self::Attachment(a) => {
107                if let attachments::AttachmentCommand::Export(e) = &a.command {
108                    Some(&e.delivery)
109                } else {
110                    None
111                }
112            }
113            _ => None,
114        }
115    }
116    pub(crate) fn validate_input(&self) -> Result<(), crate::error::AppError> {
117        if let Self::Board(a) = self {
118            if let boards::BoardCommand::Import(args) = &a.command {
119                args.validate()?;
120            }
121            if let boards::BoardCommand::ImportTrello(args) = &a.command {
122                args.validate()?;
123            }
124        }
125        if let Self::Board(a) = self {
126            if let boards::BoardCommand::Export(e) = &a.command {
127                e.validate()?;
128            }
129        }
130        if let Some(delivery) = self.export_delivery() {
131            delivery.validate()?;
132        }
133        Ok(())
134    }
135    pub fn validate_output(
136        &self,
137        format: crate::output::OutputFormat,
138    ) -> Result<(), crate::error::AppError> {
139        self.validate_input()?;
140        if let Some(delivery) = self.export_delivery() {
141            delivery.validate_output(format)?;
142        }
143        if let Self::Attachment(args) = self {
144            args.command.validate_input()?;
145            if let Some(destination) = args.command.download_destination() {
146                destination.validate_output(format)?;
147            }
148        }
149        if format == crate::output::OutputFormat::Raw && !self.supports_raw_output() {
150            return Err(crate::error::AppError::invalid_input(
151                "--output raw requires api request, an export, or an attachment download with --destination -",
152            ));
153        }
154        Ok(())
155    }
156}