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 mod integrations;
17pub mod lists;
18pub mod profile;
19pub mod rules;
20pub mod swimlanes;
21mod transfer;
22pub mod users;
23
24#[cfg(test)]
25mod tests;
26
27use clap::Subcommand;
28
29#[derive(Debug, Subcommand)]
30pub enum RootCommand {
31    /// Report domains and configure global settings, organizations, and teams.
32    Admin(Box<admin::AdminArgs>),
33    /// Inspect and manage board automation rules.
34    Rule(rules::RuleArgs),
35    /// Inspect and manage board integrations and webhook subscriptions.
36    Integration(integrations::IntegrationArgs),
37    /// Inspect and manage card dependency lines.
38    Dependency(dependencies::DependencyArgs),
39    /// Inspect, transfer and manage Wekan attachments.
40    Attachment(attachments::AttachmentArgs),
41    /// Send a low-level request to the selected Wekan server.
42    Api(api::ApiArgs),
43
44    /// Authenticate with a Wekan server.
45    Auth(auth::AuthArgs),
46
47    /// Manage named local Wekan server profiles.
48    Profile(profile::ProfileArgs),
49
50    /// Inspect and administer Wekan users.
51    User(users::UserArgs),
52
53    /// Inspect and manage Wekan boards.
54    Board(boards::BoardArgs),
55
56    /// Inspect and manage lists on Wekan boards.
57    List(lists::ListArgs),
58
59    /// Inspect and manage cards in Wekan board lists.
60    Card(Box<cards::CardArgs>),
61
62    /// Inspect and manage checklists on Wekan cards.
63    Checklist(checklists::ChecklistArgs),
64
65    /// Inspect and manage checklist items.
66    ChecklistItem(checklist_items::ChecklistItemArgs),
67
68    /// Inspect and manage comments on Wekan cards.
69    Comment(comments::CommentArgs),
70
71    /// Inspect and manage custom-field definitions.
72    CustomField(custom_fields::CustomFieldArgs),
73
74    /// Manage custom-field dropdown items.
75    CustomFieldItem(custom_field_items::CustomFieldItemArgs),
76
77    /// Inspect and manage swimlanes on Wekan boards.
78    Swimlane(swimlanes::SwimlaneArgs),
79}
80
81impl RootCommand {
82    pub fn supports_raw_output(&self) -> bool {
83        matches!(self, Self::Api(_))
84            || matches!(self, Self::Attachment(args) if args.command.download_destination().is_some_and(|d| d.is_stdout()))
85    }
86
87    pub fn validate_output(
88        &self,
89        format: crate::output::OutputFormat,
90    ) -> Result<(), crate::error::AppError> {
91        if let Self::Attachment(args) = self {
92            args.command.validate_input()?;
93            if let Some(destination) = args.command.download_destination() {
94                destination.validate_output(format)?;
95            }
96        }
97        if format == crate::output::OutputFormat::Raw && !self.supports_raw_output() {
98            return Err(crate::error::AppError::invalid_input(
99                "--output raw requires api request or an attachment download with --destination -",
100            ));
101        }
102        Ok(())
103    }
104}