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