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