Skip to main content

wekan_cli/
commands.rs

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