use crate::client::build_client;
use anyhow::{Context, Result};
use clap::Args as ClapArgs;
use std::time::{SystemTime, UNIX_EPOCH};
use turnkey_client::generated::UpdateTvcAppLiveDeploymentIntent;
#[derive(Debug, ClapArgs)]
#[command(about, long_about = None)]
pub struct Args {
#[arg(long, env = "TVC_DEPLOY_ID", value_name = "DEPLOY_ID")]
pub deploy_id: String,
}
pub async fn run(args: Args) -> Result<()> {
let auth = build_client().await?;
let intent = UpdateTvcAppLiveDeploymentIntent {
deployment_id: args.deploy_id.clone(),
};
let timestamp_ms = SystemTime::now()
.duration_since(UNIX_EPOCH)
.context("system time before unix epoch")?
.as_millis();
let result = auth
.client
.update_tvc_app_live_deployment(auth.org_id, timestamp_ms, intent)
.await
.context("failed to set TVC app live deployment")?;
println!();
println!("Set-live-deploy accepted.");
println!();
println!("Deployment ID: {}", args.deploy_id);
println!("Activity ID: {}", result.activity_id);
println!("Activity Status: {:?}", result.status);
Ok(())
}