kanidm_cli/
recycle.rs

1use crate::common::OpType;
2use crate::{handle_client_error, RecycleOpt};
3
4impl RecycleOpt {
5    pub fn debug(&self) -> bool {
6        match self {
7            RecycleOpt::List(copt) => copt.debug,
8            RecycleOpt::Get(nopt) => nopt.copt.debug,
9            RecycleOpt::Revive(nopt) => nopt.copt.debug,
10        }
11    }
12
13    pub async fn exec(&self) {
14        match self {
15            RecycleOpt::List(copt) => {
16                let client = copt.to_client(OpType::Read).await;
17                match client.recycle_bin_list().await {
18                    Ok(r) => r.iter().for_each(|e| println!("{}", e)),
19                    Err(e) => handle_client_error(e, copt.output_mode),
20                }
21            }
22            RecycleOpt::Get(nopt) => {
23                let client = nopt.copt.to_client(OpType::Read).await;
24                match client.recycle_bin_get(nopt.name.as_str()).await {
25                    Ok(Some(e)) => println!("{}", e),
26                    Ok(None) => println!("No matching entries"),
27                    Err(e) => handle_client_error(e, nopt.copt.output_mode),
28                }
29            }
30            RecycleOpt::Revive(nopt) => {
31                let client = nopt.copt.to_client(OpType::Write).await;
32                if let Err(e) = client.recycle_bin_revive(nopt.name.as_str()).await {
33                    handle_client_error(e, nopt.copt.output_mode)
34                }
35            }
36        }
37    }
38}