From d6c4a1198ac0bd90f38e23e4113a880d4f8a9075 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 19 Dec 2019 11:20:59 +0100 Subject: [PATCH] src/bin/proxmox-backup-client.rs: use async fn --- src/bin/proxmox-backup-client.rs | 82 ++++++++++++++------------------ 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 16ddc49a..721c21dc 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -2176,40 +2176,36 @@ fn catalog_mgmt_cli() -> CliCommandMap { } )] /// List running server tasks for this repo user -fn task_list(param: Value) -> Result { +async fn task_list(param: Value) -> Result { - async_main(async { - let output_format = param["output-format"].as_str().unwrap_or("text").to_owned(); - let repo = extract_repository_from_value(¶m)?; - let client = HttpClient::new(repo.host(), repo.user(), None)?; + let output_format = param["output-format"].as_str().unwrap_or("text").to_owned(); + let repo = extract_repository_from_value(¶m)?; + let client = HttpClient::new(repo.host(), repo.user(), None)?; - let limit = param["limit"].as_u64().unwrap_or(50) as usize; + let limit = param["limit"].as_u64().unwrap_or(50) as usize; - let args = json!({ - "running": true, - "start": 0, - "limit": limit, - "userfilter": repo.user(), - "store": repo.store(), - }); - let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?; + let args = json!({ + "running": true, + "start": 0, + "limit": limit, + "userfilter": repo.user(), + "store": repo.store(), + }); + let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?; - let data = &result["data"]; + let data = &result["data"]; - if output_format == "text" { - for item in data.as_array().unwrap() { - println!( - "{} {}", - item["upid"].as_str().unwrap(), - item["status"].as_str().unwrap_or("running"), - ); - } - } else { - format_and_print_result(data, &output_format); + if output_format == "text" { + for item in data.as_array().unwrap() { + println!( + "{} {}", + item["upid"].as_str().unwrap(), + item["status"].as_str().unwrap_or("running"), + ); } - - Ok::<_, Error>(()) - })?; + } else { + format_and_print_result(data, &output_format); + } Ok(Value::Null) } @@ -2228,18 +2224,14 @@ fn task_list(param: Value) -> Result { } )] /// Display the task log. -fn task_log(param: Value) -> Result { +async fn task_log(param: Value) -> Result { - async_main(async { - let repo = extract_repository_from_value(¶m)?; - let upid = tools::required_string_param(¶m, "upid")?; + let repo = extract_repository_from_value(¶m)?; + let upid = tools::required_string_param(¶m, "upid")?; - let client = HttpClient::new(repo.host(), repo.user(), None)?; + let client = HttpClient::new(repo.host(), repo.user(), None)?; - display_task_log(client, upid, true).await?; - - Ok::<_, Error>(()) - })?; + display_task_log(client, upid, true).await?; Ok(Value::Null) } @@ -2258,19 +2250,15 @@ fn task_log(param: Value) -> Result { } )] /// Try to stop a specific task. -fn task_stop(param: Value) -> Result { +async fn task_stop(param: Value) -> Result { - async_main(async { - let repo = extract_repository_from_value(¶m)?; - let upid_str = tools::required_string_param(¶m, "upid")?; + let repo = extract_repository_from_value(¶m)?; + let upid_str = tools::required_string_param(¶m, "upid")?; - let mut client = HttpClient::new(repo.host(), repo.user(), None)?; + let mut client = HttpClient::new(repo.host(), repo.user(), None)?; - let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); - let _ = client.delete(&path, None).await?; - - Ok::<_, Error>(()) - })?; + let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); + let _ = client.delete(&path, None).await?; Ok(Value::Null) }