From bfc511c6e7705a5a18af451284795242a20f7904 Mon Sep 17 00:00:00 2001 From: Jonathan Grahl Date: Thu, 12 Dec 2024 17:04:10 +0100 Subject: [PATCH] fix: print deployment info --- src/api/mod.rs | 17 +++++++++-------- src/commands/environments.rs | 13 ++++++++----- src/commands/services.rs | 5 +++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 32e876e..31bb13a 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -79,7 +79,6 @@ impl APIClient { ) -> anyhow::Result { let url = format!("{}/orgs/{}/envs/{}/svcs", self.base_url, org_name, env_name); let response: String = self.get(&url, token)?.error_for_status()?.text()?; - println!("{}", response.clone()); serde_json::from_str(response.as_str()).with_context(|| "Failed to deserialize response") } @@ -119,7 +118,6 @@ impl APIClient { match response.status() { StatusCode::OK => { let text = &response.text()?; - println!("{}", text); Ok(serde_json::from_str(text) .with_context(|| "Failed to deserialize environments")?) } @@ -191,16 +189,19 @@ impl APIClient { let url = format!("{}/orgs/{}/envs/{}/svcs", self.base_url, org_name, env_name); let body = serde_json::to_string(&service)?; let response = self.post_str(&url, token, body)?; - match response.status() { - StatusCode::CREATED => Ok(serde_json::from_str(&response.text()?) - .with_context(|| "Failed to deserialize service")?), + let status = response.status(); + let text = response.text()?; + match status { + StatusCode::CREATED => { + Ok(serde_json::from_str(&text).with_context(|| "Failed to deserialize service")?) + } StatusCode::UNAUTHORIZED => Err(anyhow!("Unauthorized, please login first")), StatusCode::NOT_FOUND => Err(anyhow!("Org or environment not found")), - StatusCode::BAD_REQUEST => Err(anyhow!("Bad request: {}", response.text()?)), + StatusCode::BAD_REQUEST => Err(anyhow!("Bad request: {}", text)), _ => Err(anyhow!( "Failed to deploy service. API returned {} - {}", - response.status(), - response.text()? + status, + text )), } } diff --git a/src/commands/environments.rs b/src/commands/environments.rs index add1054..40abb82 100644 --- a/src/commands/environments.rs +++ b/src/commands/environments.rs @@ -59,9 +59,12 @@ impl Create { .get_token() .ok_or_else(|| anyhow!("No token found. Please login first."))?; - let response = base - .api_client() - .create_environment(token, &self.name, &org_name, self.copy_from.as_deref())?; + let response = base.api_client().create_environment( + token, + &self.name, + &org_name, + self.copy_from.as_deref(), + )?; let table = Table::new([response]).to_string(); println!("{}", table); @@ -83,7 +86,8 @@ impl List { let response = base.api_client().get_environments(token, &org_name)?; - println!("{:?}", response); + let table = Table::new(response.environments).to_string(); + println!("{}", table); Ok(()) } @@ -109,7 +113,6 @@ impl Delete { println!("Delete cancelled"); return Ok(()); } - base.api_client() .delete_environment(token, &org_name, &self.name)?; diff --git a/src/commands/services.rs b/src/commands/services.rs index 029629f..93a41dd 100644 --- a/src/commands/services.rs +++ b/src/commands/services.rs @@ -125,13 +125,14 @@ impl Deploy { } } - let _result = base.api_client().deploy_service( + let result = base.api_client().deploy_service( token, &org_name, &manifest.environment, manifest.service, )?; - println!("Service deployed."); + + println!("{:?}", result); Ok(()) }