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(crate) mod exports;
17pub(crate) mod imports;
18pub mod integrations;
19pub mod lists;
20pub mod profile;
21pub mod rules;
22pub mod skill;
23pub mod swimlanes;
24pub mod system;
25mod transfer;
26pub mod users;
27
28#[cfg(test)]
29mod tests;
30
31use clap::Subcommand;
32
33#[derive(Debug, Subcommand)]
34pub enum RootCommand {
35 Skill(skill::SkillArgs),
37 System(system::SystemArgs),
39 Admin(Box<admin::AdminArgs>),
41 Rule(rules::RuleArgs),
43 Integration(integrations::IntegrationArgs),
45 Dependency(dependencies::DependencyArgs),
47 Attachment(attachments::AttachmentArgs),
49 Api(api::ApiArgs),
51
52 Auth(auth::AuthArgs),
54
55 Profile(profile::ProfileArgs),
57
58 User(users::UserArgs),
60
61 Board(boards::BoardArgs),
63
64 List(lists::ListArgs),
66
67 Card(Box<cards::CardArgs>),
69
70 Checklist(checklists::ChecklistArgs),
72
73 Comment(comments::CommentArgs),
75
76 CustomField(custom_fields::CustomFieldArgs),
78
79 Swimlane(swimlanes::SwimlaneArgs),
81}
82
83impl RootCommand {
84 pub fn supports_raw_output(&self) -> bool {
85 matches!(self, Self::Api(_))
86 || self.export_delivery().is_some_and(|d| d.is_stdout())
87 || matches!(self, Self::Attachment(args) if args.command.download_destination().is_some_and(|d| d.is_stdout()))
88 }
89
90 pub(crate) fn export_delivery(&self) -> Option<&exports::DeliveryArgs> {
91 match self {
92 Self::Board(a) => {
93 if let boards::BoardCommand::Export(e) = &a.command {
94 Some(&e.delivery)
95 } else {
96 None
97 }
98 }
99 Self::Card(a) => {
100 if let cards::CardCommand::Export(e) = &a.command {
101 Some(&e.delivery)
102 } else {
103 None
104 }
105 }
106 Self::Attachment(a) => {
107 if let attachments::AttachmentCommand::Export(e) = &a.command {
108 Some(&e.delivery)
109 } else {
110 None
111 }
112 }
113 _ => None,
114 }
115 }
116 pub(crate) fn validate_input(&self) -> Result<(), crate::error::AppError> {
117 if let Self::Board(a) = self {
118 if let boards::BoardCommand::Import(args) = &a.command {
119 args.validate()?;
120 }
121 if let boards::BoardCommand::ImportTrello(args) = &a.command {
122 args.validate()?;
123 }
124 }
125 if let Self::Board(a) = self {
126 if let boards::BoardCommand::Export(e) = &a.command {
127 e.validate()?;
128 }
129 }
130 if let Some(delivery) = self.export_delivery() {
131 delivery.validate()?;
132 }
133 Ok(())
134 }
135 pub fn validate_output(
136 &self,
137 format: crate::output::OutputFormat,
138 ) -> Result<(), crate::error::AppError> {
139 self.validate_input()?;
140 if let Some(delivery) = self.export_delivery() {
141 delivery.validate_output(format)?;
142 }
143 if let Self::Attachment(args) = self {
144 args.command.validate_input()?;
145 if let Some(destination) = args.command.download_destination() {
146 destination.validate_output(format)?;
147 }
148 }
149 if format == crate::output::OutputFormat::Raw && !self.supports_raw_output() {
150 return Err(crate::error::AppError::invalid_input(
151 "--output raw requires api request, an export, or an attachment download with --destination -",
152 ));
153 }
154 Ok(())
155 }
156}