Skip to content

Commit

Permalink
cargo-shuttle: add the beta deployment status cmd handler
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianbarbu committed Apr 17, 2024
1 parent b8c5b84 commit ec57108
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum DeploymentCommand {
/// View status of a deployment
Status {
/// ID of deployment to get status for
id: Uuid,
id: String,
},
}

Expand Down
10 changes: 10 additions & 0 deletions cargo-shuttle/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ impl ShuttleApiClient {
self.get(path).await
}

pub async fn deployment_status(
&self,
project: &str,
deployment_id: &str,
) -> Result<deployment::EcsResponse> {
let path = format!("/projects/{project}/deployments/{deployment_id}");

self.get(path).await
}

pub async fn get_deployment_details(
&self,
project: &str,
Expand Down
36 changes: 27 additions & 9 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ impl Shuttle {
}
if matches!(
args.cmd,
Command::Deployment(..)
| Command::Resource(..)
Command::Resource(..)
| Command::Stop
| Command::Clean
| Command::Status
Expand Down Expand Up @@ -221,9 +220,14 @@ impl Shuttle {
Command::Status => self.status().await,
Command::Logs(logs_args) => self.logs(logs_args).await,
Command::Deployment(DeploymentCommand::List { page, limit, raw }) => {
if self.beta {
unimplemented!();
}
self.deployments_list(page, limit, raw).await
}
Command::Deployment(DeploymentCommand::Status { id }) => self.deployment_get(id).await,
Command::Deployment(DeploymentCommand::Status { id }) => {
self.deployment_get(id.as_str()).await
}
Command::Resource(ResourceCommand::List { raw, show_secrets }) => {
self.resources_list(raw, show_secrets).await
}
Expand Down Expand Up @@ -952,14 +956,28 @@ impl Shuttle {
Ok(CommandOutcome::Ok)
}

async fn deployment_get(&self, deployment_id: Uuid) -> Result<CommandOutcome> {
async fn deployment_get(&self, deployment_id: &str) -> Result<CommandOutcome> {
let client = self.client.as_ref().unwrap();
let deployment = client
.get_deployment_details(self.ctx.project_name(), &deployment_id)
.await
.map_err(suggestions::deployment::get_deployment_status_failure)?;

println!("{deployment}");
if self.beta {
let deployment = client
.deployment_status(self.ctx.project_name(), deployment_id)
.await
.map_err(suggestions::deployment::get_deployment_status_failure)?;
deployment.colored_println();
} else {
let deployment = client
.get_deployment_details(
self.ctx.project_name(),
&Uuid::from_str(deployment_id).map_err(|err| {
anyhow!("Provided deployment id is not a valid UUID: {err}")
})?,
)
.await
.map_err(suggestions::deployment::get_deployment_status_failure)?;

println!("{deployment}");
}

Ok(CommandOutcome::Ok)
}
Expand Down
8 changes: 6 additions & 2 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ impl EcsResponse {
);

let state_with_uri = match self.running_id {
None => format!("{latest_state} ({})", self.uri),
Some(_) => latest_state,
None if EcsState::Running == self.latest_deployment_state
|| EcsState::InProgress == self.latest_deployment_state =>
{
format!("{latest_state} ({})", self.uri)
}
_ => latest_state,
};

println!(
Expand Down

0 comments on commit ec57108

Please sign in to comment.