Skip to main content

wekan_cli/
commands.rs

1pub mod api;
2pub mod auth;
3pub(crate) mod authenticated;
4pub mod boards;
5pub mod cards;
6pub(crate) mod client_error;
7pub mod comments;
8pub(crate) mod credential_ops;
9pub mod lists;
10pub mod profile;
11pub mod swimlanes;
12pub mod users;
13
14use clap::Subcommand;
15
16use crate::{
17    client::WekanClientFactory,
18    command_result::CommandSuccess,
19    config::profiles::ProfileStore,
20    credentials::{CredentialStore, SecretInputProvider},
21    error::AppError,
22    input::ConfirmationProvider,
23};
24
25#[derive(Debug, Subcommand)]
26pub enum RootCommand {
27    /// Send a low-level request to the selected Wekan server.
28    Api(api::ApiArgs),
29
30    /// Authenticate with a Wekan server.
31    Auth(auth::AuthArgs),
32
33    /// Manage named local Wekan server profiles.
34    Profile(profile::ProfileArgs),
35
36    /// Inspect and administer Wekan users.
37    User(users::UserArgs),
38
39    /// Inspect and manage Wekan boards.
40    Board(boards::BoardArgs),
41
42    /// Inspect and manage lists on Wekan boards.
43    List(lists::ListArgs),
44
45    /// Inspect and manage cards in Wekan board lists.
46    Card(Box<cards::CardArgs>),
47
48    /// Inspect and manage comments on Wekan cards.
49    Comment(comments::CommentArgs),
50
51    /// Inspect and manage swimlanes on Wekan boards.
52    Swimlane(swimlanes::SwimlaneArgs),
53}
54
55impl RootCommand {
56    pub const fn supports_raw_output(&self) -> bool {
57        matches!(self, Self::Api(_))
58    }
59}
60
61pub(crate) enum PreparedCommand<'command, 'store> {
62    Api {
63        args: api::ApiArgs,
64        client_factory: &'command WekanClientFactory,
65    },
66    Auth {
67        command: auth::PreparedAuthCommand<'command, 'store>,
68    },
69    Profile {
70        args: profile::ProfileArgs,
71    },
72    User {
73        args: users::UserArgs,
74        client_factory: &'command WekanClientFactory,
75    },
76    Board {
77        args: boards::BoardArgs,
78        client_factory: &'command WekanClientFactory,
79    },
80    List {
81        args: lists::ListArgs,
82        client_factory: &'command WekanClientFactory,
83    },
84    Card {
85        args: Box<cards::CardArgs>,
86        client_factory: &'command WekanClientFactory,
87    },
88    Comment {
89        args: comments::CommentArgs,
90        client_factory: &'command WekanClientFactory,
91    },
92    Swimlane {
93        args: swimlanes::SwimlaneArgs,
94        client_factory: &'command WekanClientFactory,
95    },
96}
97
98pub(crate) async fn dispatch(
99    command: PreparedCommand<'_, '_>,
100    credential_store: &dyn CredentialStore,
101    secret_input: &dyn SecretInputProvider,
102    profile_store: &dyn ProfileStore,
103    confirmation: &dyn ConfirmationProvider,
104) -> Result<CommandSuccess, AppError> {
105    match command {
106        PreparedCommand::Api {
107            args,
108            client_factory,
109        } => api::dispatch(args.command, client_factory, credential_store, confirmation).await,
110        PreparedCommand::Auth { command } => {
111            auth::dispatch(command, credential_store, secret_input, confirmation).await
112        }
113        PreparedCommand::Profile { args } => {
114            profile::dispatch(args.command, profile_store, credential_store, confirmation)
115        }
116        PreparedCommand::User {
117            args,
118            client_factory,
119        } => {
120            users::dispatch(
121                args.command,
122                client_factory,
123                credential_store,
124                secret_input,
125                confirmation,
126            )
127            .await
128        }
129        PreparedCommand::Board {
130            args,
131            client_factory,
132        } => boards::dispatch(args.command, client_factory, credential_store, confirmation).await,
133        PreparedCommand::List {
134            args,
135            client_factory,
136        } => lists::dispatch(args.command, client_factory, credential_store, confirmation).await,
137        PreparedCommand::Card {
138            args,
139            client_factory,
140        } => cards::dispatch(args.command, client_factory, credential_store, confirmation).await,
141        PreparedCommand::Comment {
142            args,
143            client_factory,
144        } => comments::dispatch(args.command, client_factory, credential_store, confirmation).await,
145        PreparedCommand::Swimlane {
146            args,
147            client_factory,
148        } => {
149            swimlanes::dispatch(args.command, client_factory, credential_store, confirmation).await
150        }
151    }
152}