wekan_cli/commands/admin/
domains.rs1use crate::{
2 client::WekanClientFactory,
3 command_result::{AdminDomainCollectionSuccess, CommandSuccess},
4 commands::{authenticated::AuthenticatedContext, client_error::map_client_error},
5 credentials::CredentialStore,
6 error::AppError,
7 redaction::Redactor,
8};
9use clap::{Args, Subcommand};
10
11#[derive(Debug, Args)]
12pub struct DomainArgs {
13 #[command(subcommand)]
14 pub command: DomainCommand,
15}
16#[derive(Debug, Subcommand)]
17pub enum DomainCommand {
18 List,
20}
21pub(super) async fn execute(
22 command: DomainCommand,
23 factory: &WekanClientFactory,
24 store: &dyn CredentialStore,
25) -> Result<CommandSuccess, AppError> {
26 match command {
27 DomainCommand::List => {
28 let context = AuthenticatedContext::load(factory, store)?;
29 let domains = context
30 .client()
31 .admin_domains(context.record().token())
32 .await
33 .map_err(|e| {
34 map_client_error(
35 e,
36 &Redactor::with_secret(context.record().token()),
37 "admin domain list",
38 )
39 })?;
40 Ok(CommandSuccess::AdminDomains(AdminDomainCollectionSuccess {
41 domains,
42 }))
43 }
44 }
45}