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 Attachment(attachments::AttachmentArgs),
25 Api(api::ApiArgs),
27
28 Auth(auth::AuthArgs),
30
31 Profile(profile::ProfileArgs),
33
34 User(users::UserArgs),
36
37 Board(boards::BoardArgs),
39
40 List(lists::ListArgs),
42
43 Card(Box<cards::CardArgs>),
45
46 Checklist(checklists::ChecklistArgs),
48
49 ChecklistItem(checklist_items::ChecklistItemArgs),
51
52 Comment(comments::CommentArgs),
54
55 CustomField(custom_fields::CustomFieldArgs),
57
58 CustomFieldItem(custom_field_items::CustomFieldItemArgs),
60
61 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}