src/bin/proxmox-backup-client.rs: cleanup - factor out view_task_result()
This commit is contained in:
		| @ -146,6 +146,23 @@ fn complete_repository(_arg: &str, _param: &HashMap<String, String>) -> Vec<Stri | |||||||
|     result |     result | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async fn view_task_result( | ||||||
|  |     client: HttpClient, | ||||||
|  |     result: Value, | ||||||
|  |     output_format: &str, | ||||||
|  | ) -> Result<(), Error> { | ||||||
|  |     let data = &result["data"]; | ||||||
|  |     if output_format == "text" { | ||||||
|  |         if let Some(upid) = data.as_str() { | ||||||
|  |             display_task_log(client, upid, true).await?; | ||||||
|  |         } | ||||||
|  |     } else { | ||||||
|  |         format_and_print_result(&data, &output_format); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Ok(()) | ||||||
|  | } | ||||||
|  |  | ||||||
| async fn backup_directory<P: AsRef<Path>>( | async fn backup_directory<P: AsRef<Path>>( | ||||||
|     client: &BackupWriter, |     client: &BackupWriter, | ||||||
|     dir_path: P, |     dir_path: P, | ||||||
| @ -547,19 +564,9 @@ fn start_garbage_collection( | |||||||
|  |  | ||||||
|         record_repository(&repo); |         record_repository(&repo); | ||||||
|  |  | ||||||
|         let data = &result["data"]; |         view_task_result(client, result, &output_format).await | ||||||
|         if output_format == "text" { |  | ||||||
|             if let Some(upid) = data.as_str() { |  | ||||||
|                 display_task_log(client, upid, true).await?; |  | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             format_and_print_result(&data, &output_format); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         Ok::<_, Error>(()) |  | ||||||
|     })?; |     })?; | ||||||
|  |  | ||||||
|  |  | ||||||
|     Ok(Value::Null) |     Ok(Value::Null) | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -1167,17 +1174,8 @@ fn prune( | |||||||
|  |  | ||||||
|         record_repository(&repo); |         record_repository(&repo); | ||||||
|  |  | ||||||
|         let data = &result["data"]; |         view_task_result(client, result, &output_format).await | ||||||
|         if output_format == "text" { |      })?; | ||||||
|             if let Some(upid) = data.as_str() { |  | ||||||
|                 display_task_log(client, upid, true).await?; |  | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             format_and_print_result(&data, &output_format); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         Ok::<_, Error>(()) |  | ||||||
|     })?; |  | ||||||
|  |  | ||||||
|     Ok(Value::Null) |     Ok(Value::Null) | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user