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