| 269 | } |
| 270 | |
| 271 | fn process(values: &[serde_json::Value], action: &Action) -> Result<(), EachError> { |
| 272 | let results: Result<Vec<()>, EachError> = values |
| 273 | .par_iter() |
| 274 | .map(|value| -> Result<(), EachError> { |
| 275 | let cmd = action.prepare(value).map_err(|e| EachError::Data { |
| 276 | message: format!("failed to prepare command: {:?}", e), |
| 277 | })?; |
| 278 | |
| 279 | let run = if action.prompt { |
| 280 | let prompt = action.prompt(&cmd, value).map_err(|e| EachError::Data { |
| 281 | message: format!("failed to render stdin: {:?}", e), |
| 282 | })?; |
| 283 | |
| 284 | Confirm::new().with_prompt(&prompt).interact()? |
| 285 | } else { |
| 286 | true |
| 287 | }; |
| 288 | |
| 289 | if run { |
| 290 | action.run(cmd).map_err(|e| EachError::Data { |
| 291 | message: format!("failed to run command: {:?}", e), |
| 292 | })?; |
| 293 | } |
| 294 | |
| 295 | Ok(()) |
| 296 | }) |
| 297 | .collect(); |
| 298 | |
| 299 | results.map(|_| ()) |
| 300 | } |