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