(command: &Option<Command>, config: &Config, cli: &Cli)
| 28 | } |
| 29 | |
| 30 | pub(crate) async fn handle(command: &Option<Command>, config: &Config, cli: &Cli) { |
| 31 | match command { |
| 32 | Some(Command::Add { file }) => connect(config, cli) |
| 33 | .await |
| 34 | .pipe_borrow(|client| { |
| 35 | load_files(file, cli).then(|values| { |
| 36 | join_all( |
| 37 | values |
| 38 | .into_iter() |
| 39 | .map(|value| client.add_maintenance(value)), |
| 40 | ) |
| 41 | }) |
| 42 | }) |
| 43 | .await |
| 44 | .into_iter() |
| 45 | .collect::<Result<Vec<_>>>() |
| 46 | .map(|result| result.into_iter().collect_or_unwrap()) |
| 47 | .print_result(cli), |
| 48 | |
| 49 | Some(Command::Edit { file }) => connect(config, cli) |
| 50 | .await |
| 51 | .pipe_borrow(|client| { |
| 52 | load_files(file, cli).then(|values| { |
| 53 | join_all( |
| 54 | values |
| 55 | .into_iter() |
| 56 | .map(|value| client.edit_maintenance(value)), |
| 57 | ) |
| 58 | }) |
| 59 | }) |
| 60 | .await |
| 61 | .into_iter() |
| 62 | .collect::<Result<Vec<_>>>() |
| 63 | .map(|result| result.into_iter().collect_or_unwrap()) |
| 64 | .print_result(cli), |
| 65 | |
| 66 | Some(Command::Get { id }) => connect(config, cli) |
| 67 | .await |
| 68 | .pipe_borrow(|client| join_all(id.iter().map(|id| client.get_maintenance(*id)))) |
| 69 | .await |
| 70 | .into_iter() |
| 71 | .collect::<Result<Vec<_>>>() |
| 72 | .map(|result| result.into_iter().collect_or_unwrap()) |
| 73 | .print_result(cli), |
| 74 | |
| 75 | Some(Command::Delete { id }) => connect(config, cli) |
| 76 | .await |
| 77 | .pipe_borrow(|client| join_all(id.iter().map(|id| client.delete_maintenance(*id)))) |
| 78 | .await |
| 79 | .into_iter() |
| 80 | .collect::<Result<Vec<_>>>() |
| 81 | .map(|result| result.into_iter().collect_or_unwrap()) |
| 82 | .print_result(cli), |
| 83 | |
| 84 | Some(Command::List {}) => connect(config, cli) |
| 85 | .await |
| 86 | .get_maintenances() |
| 87 | .await |
nothing calls this directly
no test coverage detected