From 12b815305bcd1f1423ef4b2acc83b043b87ca92d Mon Sep 17 00:00:00 2001 From: Manuel Dewald Date: Thu, 5 Jun 2025 10:03:02 +0200 Subject: [PATCH] feat(env): Read WORKSPACE_ID alternatively * Add one-liner to add the CLI to a Codesphere workspace * fix parameter names in set-env-vars command * fix type in readme * read env var as set in workspace by default Signed-off-by: Manuel Dewald --- README.md | 14 +++++++++++--- cli/cmd/set-env-vars.go | 4 ++-- pkg/cs/env.go | 7 ++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f8b36c7..da0cee9 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,18 @@ This project is licensed under the Apache License, Version 2.0 - see the [LICENS You can install the Codesphere CLI in a few ways: +#### Install inside a Codesphere Workspace + +To use the CLI inside a Codesphere workspace, install it using the following command: + +``` +wget -qO- 'https://api.github.com/repos/codesphere-cloud/cs-go/releases/latest' | grep linux_amd64 | grep browser_download_url | sed s/.*https/https/ | sed s/\".*$// | xargs wget -O $HOME/.local/bin/cs && chmod +x $HOME/.local/bin/cs +``` + #### Using GitHub CLI (`gh`) If you have the [GitHub CLI](https://cli.github.com/) installed, you can install the `cs` CLI with a command like the following. -Not that some commands may require you to elevate to the root user with `sudo`. +Note that some commands may require you to elevate to the root user with `sudo`. ##### ARM Mac @@ -38,7 +46,7 @@ chmod +x /usr/local/bin/cs #### Using `wget` This option requires to have the `wget` and `jq` utils installed. Download the `cs` CLI and add permissions to run it with the following commands: -Not that some commands may require you to elevate to the root user with `sudo`. +Note that some commands may require you to elevate to the root user with `sudo`. ##### ARM Mac @@ -59,7 +67,7 @@ chmod +x /usr/local/bin/cs #### Manual Download You can also download the pre-compiled binaries from the [Codesphere CLI Releases page](https://github.com/codesphere-cloud/cs-go/releases). -Not that some commands may require you to elevate to the root user with `sudo`. +Note that some commands may require you to elevate to the root user with `sudo`. 1. Go to the [latest release](https://github.com/codesphere-cloud/cs-go/releases/latest). diff --git a/cli/cmd/set-env-vars.go b/cli/cmd/set-env-vars.go index ba07a2a..5235a96 100644 --- a/cli/cmd/set-env-vars.go +++ b/cli/cmd/set-env-vars.go @@ -28,8 +28,8 @@ func AddSetEnvVarCmd(p *cobra.Command, opts GlobalOptions) { Short: "set env vars", Long: `set environment variables for your workspace`, Example: out.FormatExampleCommands("set-env", []out.Example{ - {Cmd: "--workspace-id --env foo=bar", Desc: "Set single environment variable"}, - {Cmd: "--workspace-id --env foo=bar --env hello=world", Desc: "Set multiple environment variables"}, + {Cmd: "--workspace --env-var foo=bar", Desc: "Set single environment variable"}, + {Cmd: "--workspace --env-var foo=bar --env-var hello=world", Desc: "Set multiple environment variables"}, }), }, Opts: SetEnvVarOptions{GlobalOptions: opts}, diff --git a/pkg/cs/env.go b/pkg/cs/env.go index e7c4374..032cf50 100644 --- a/pkg/cs/env.go +++ b/pkg/cs/env.go @@ -26,7 +26,12 @@ func (e *Environment) GetApiToken() (string, error) { } func (e *Environment) GetWorkspaceId() (int, error) { - return e.ReadNumericEnv("CS_WORKSPACE_ID") + prefixedId, err := e.ReadNumericEnv("CS_WORKSPACE_ID") + if prefixedId != -1 && err == nil { + return prefixedId, nil + } + + return e.ReadNumericEnv("WORKSPACE_ID") } func (e *Environment) GetTeamId() (int, error) {