diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 284fd13..d41fdc4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,7 +39,7 @@ jobs: ./target key: build-cargo-registry-${{matrix.TARGET}} - - uses: mlugg/setup-zig@aa9ad5c14eb3452e235a441c4f9a8e89f20d97bd + - uses: mlugg/setup-zig@7dccf5e6d09267c55f815f2db29495f30ba2ebca - name: Install cargo-zigbuild run: cargo install cargo-zigbuild diff --git a/src/api/types.rs b/src/api/types.rs index 89d4e8c..1fca75a 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -64,7 +64,7 @@ pub struct CreateEnvironmentResponse { #[derive(Serialize, Deserialize, Debug)] pub struct ListServicesResponse { - pub services: Vec, + pub services: Vec, } #[derive(Debug, Serialize, Deserialize, PartialEq)] @@ -123,6 +123,23 @@ pub struct ComposeService { pub host_aliases: DisplayVec, } +#[derive(Debug, Serialize, Deserialize, PartialEq, Tabled)] +pub struct ServiceResponse { + pub name: String, + + #[serde(default)] + pub containers: DisplayVec, + + #[serde(default)] + pub volumes: DisplayVec, + + #[serde(default)] + pub host_aliases: DisplayVec, + + #[serde(default)] + pub url: String, +} + #[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)] pub struct VolumeMount { pub volume_name: String, diff --git a/src/commands/services.rs b/src/commands/services.rs index 8e96d6e..9e69b8b 100644 --- a/src/commands/services.rs +++ b/src/commands/services.rs @@ -44,6 +44,7 @@ impl Services { Some(Commands::ImageName(image_name)) => image_name.execute(base), Some(Commands::List(list)) => list.execute(base), Some(Commands::Delete(delete)) => delete.execute(base), + Some(Commands::GetURL(get_url)) => get_url.execute(base), None => Ok(()), } } @@ -61,6 +62,9 @@ pub enum Commands { List(List), /// Delete a service Delete(Delete), + /// Get the URL of a service + #[command(name = "get-url")] + GetURL(GetURL), } #[derive(Debug, Parser)] @@ -769,3 +773,35 @@ fn write_manifest(path: &str, compose: &ComposeFile) -> Result<()> { file.write_all(yaml.as_bytes())?; Ok(()) } + +#[derive(Debug, Parser)] +pub struct GetURL { + #[arg(help = "Name of the service")] + name: String, + #[arg(long, help = "Environment the service is in")] + env: String, +} + +impl GetURL { + pub fn execute(self, base: CommandBase) -> Result<()> { + let tenant_name = base.get_tenant()?; + let project_name = base.get_project()?; + let token = base + .user_config() + .get_token() + .ok_or_else(|| anyhow!("No token found. Please login first."))?; + + let response = base + .api_client() + .get_services(token, &tenant_name, &project_name, &self.env)?; + + let service = response + .services + .iter() + .find(|s| s.name == self.name) + .ok_or_else(|| anyhow!("Service '{}' not found in environment '{}'", self.name, self.env))?; + + println!("{}", service.url); + Ok(()) + } +}