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