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 comments on Wekan cards.
66    Comment(comments::CommentArgs),
67
68    /// Inspect and manage custom-field definitions.
69    CustomField(custom_fields::CustomFieldArgs),
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}