Skip to content

Commit 0daf69b

Browse files
authored
feat(env): Read WORKSPACE_ID alternatively (#36)
* 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 <manuel@codesphere.com>
1 parent 2b2046b commit 0daf69b

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ This project is licensed under the Apache License, Version 2.0 - see the [LICENS
1616

1717
You can install the Codesphere CLI in a few ways:
1818

19+
#### Install inside a Codesphere Workspace
20+
21+
To use the CLI inside a Codesphere workspace, install it using the following command:
22+
23+
```
24+
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
25+
```
26+
1927
#### Using GitHub CLI (`gh`)
2028

2129
If you have the [GitHub CLI](https://cli.github.com/) installed, you can install the `cs` CLI with a command like the following.
22-
Not that some commands may require you to elevate to the root user with `sudo`.
30+
Note that some commands may require you to elevate to the root user with `sudo`.
2331

2432
##### ARM Mac
2533

@@ -38,7 +46,7 @@ chmod +x /usr/local/bin/cs
3846
#### Using `wget`
3947

4048
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:
41-
Not that some commands may require you to elevate to the root user with `sudo`.
49+
Note that some commands may require you to elevate to the root user with `sudo`.
4250

4351
##### ARM Mac
4452

@@ -59,7 +67,7 @@ chmod +x /usr/local/bin/cs
5967
#### Manual Download
6068

6169
You can also download the pre-compiled binaries from the [Codesphere CLI Releases page](https://github.com/codesphere-cloud/cs-go/releases).
62-
Not that some commands may require you to elevate to the root user with `sudo`.
70+
Note that some commands may require you to elevate to the root user with `sudo`.
6371

6472
1. Go to the [latest release](https://github.com/codesphere-cloud/cs-go/releases/latest).
6573

cli/cmd/set-env-vars.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func AddSetEnvVarCmd(p *cobra.Command, opts GlobalOptions) {
2828
Short: "set env vars",
2929
Long: `set environment variables for your workspace`,
3030
Example: out.FormatExampleCommands("set-env", []out.Example{
31-
{Cmd: "--workspace-id <workspace-id> --env foo=bar", Desc: "Set single environment variable"},
32-
{Cmd: "--workspace-id <workspace-id> --env foo=bar --env hello=world", Desc: "Set multiple environment variables"},
31+
{Cmd: "--workspace <workspace-id> --env-var foo=bar", Desc: "Set single environment variable"},
32+
{Cmd: "--workspace <workspace-id> --env-var foo=bar --env-var hello=world", Desc: "Set multiple environment variables"},
3333
}),
3434
},
3535
Opts: SetEnvVarOptions{GlobalOptions: opts},

pkg/cs/env.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ func (e *Environment) GetApiToken() (string, error) {
2626
}
2727

2828
func (e *Environment) GetWorkspaceId() (int, error) {
29-
return e.ReadNumericEnv("CS_WORKSPACE_ID")
29+
prefixedId, err := e.ReadNumericEnv("CS_WORKSPACE_ID")
30+
if prefixedId != -1 && err == nil {
31+
return prefixedId, nil
32+
}
33+
34+
return e.ReadNumericEnv("WORKSPACE_ID")
3035
}
3136

3237
func (e *Environment) GetTeamId() (int, error) {

0 commit comments

Comments
 (0)