Skip to content

Commit 9892e3d

Browse files
authored
feat: Print requests and responses on when passing -v flag (#191)
* feat: Print requests and responses on when passing -v flag * chore(docs): Auto-update docs and licenses Signed-off-by: NautiluX <2600004+NautiluX@users.noreply.github.com> --------- Signed-off-by: NautiluX <2600004+NautiluX@users.noreply.github.com> Co-authored-by: NautiluX <2600004+NautiluX@users.noreply.github.com>
1 parent e857c5b commit 9892e3d

17 files changed

+84
-79
lines changed

api/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ type Configuration struct {
2424
BaseUrl *url.URL
2525
// Codesphere api token
2626
Token string
27+
28+
// Verbose output for debugging
29+
Verbose bool
2730
}
2831

2932
func (c Configuration) GetApiUrl() *url.URL {
@@ -52,6 +55,7 @@ func NewClient(ctx context.Context, opts Configuration) *Client {
5255
cfg.Servers = []openapi_client.ServerConfiguration{{
5356
URL: opts.BaseUrl.String(),
5457
}}
58+
cfg.Debug = opts.Verbose
5559
return NewClientWithCustomDeps(ctx, opts, openapi_client.NewAPIClient(cfg), &RealTime{})
5660
}
5761

cli/cmd/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func NewClient(opts GlobalOptions) (Client, error) {
5151
client := api.NewClient(context.Background(), api.Configuration{
5252
BaseUrl: apiUrl,
5353
Token: token,
54+
Verbose: opts.Verbose,
5455
})
5556
return client, nil
5657
}

cli/cmd/create_workspace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var _ = Describe("CreateWorkspace", func() {
5656
Opts: cmd.CreateWorkspaceOpts{
5757
GlobalOptions: cmd.GlobalOptions{
5858
Env: mockEnv,
59-
TeamId: &teamId,
59+
TeamId: teamId,
6060
},
6161
Env: &env,
6262
Repo: repo,

cli/cmd/curl_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var _ = Describe("Curl", func() {
4646
Opts: cmd.CurlOptions{
4747
GlobalOptions: cmd.GlobalOptions{
4848
Env: mockEnv,
49-
WorkspaceId: &wsId,
49+
WorkspaceId: wsId,
5050
},
5151
Timeout: 30 * time.Second,
5252
Executor: mockExecutor,

cli/cmd/delete_workspace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var _ = Describe("DeleteWorkspace", func() {
3333
Opts: cmd.DeleteWorkspaceOpts{
3434
GlobalOptions: cmd.GlobalOptions{
3535
Env: mockEnv,
36-
WorkspaceId: &wsId,
36+
WorkspaceId: wsId,
3737
},
3838
Confirmed: &confirmed,
3939
},

cli/cmd/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var _ = Describe("Exec", func() {
3434
Opts: cmd.ExecOptions{
3535
GlobalOptions: cmd.GlobalOptions{
3636
Env: mockEnv,
37-
WorkspaceId: &wsId,
37+
WorkspaceId: wsId,
3838
},
3939
EnvVar: &envVars,
4040
WorkDir: &workDir,

cli/cmd/generate_docker_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ var _ = Describe("GenerateDocker", func() {
4444
Opts: &cmd.GenerateDockerOpts{
4545
GenerateOpts: &cmd.GenerateOpts{
4646
GlobalOptions: cmd.GlobalOptions{
47-
Env: mockEnv,
47+
WorkspaceId: -1,
48+
Env: mockEnv,
4849
},
4950
Input: defaultInput,
5051
Output: defaultOutput,
@@ -109,16 +110,17 @@ var _ = Describe("GenerateDocker", func() {
109110
})
110111

111112
Context("when workspace ID is set in the env var", func() {
113+
BeforeEach(func() {
114+
wsId = 99
115+
})
112116
It("should use the workspace ID from environment", func() {
113-
envWsId := 99
114-
mockEnv.EXPECT().GetWorkspaceId().Return(envWsId, nil)
115-
116117
cmd := &cmd.GenerateDockerCmd{
117118
Opts: &cmd.GenerateDockerOpts{
118119
GenerateOpts: &cmd.GenerateOpts{
119120
GlobalOptions: cmd.GlobalOptions{
120-
Env: mockEnv,
121-
// WorkspaceId is nil, so it will use env var
121+
Env: mockEnv,
122+
WorkspaceId: -1,
123+
// WorkspaceId is -1 (default), so it will use env var
122124
},
123125
},
124126
BaseImage: "alpine:latest",
@@ -128,7 +130,8 @@ var _ = Describe("GenerateDocker", func() {
128130
ws := api.Workspace{
129131
GitUrl: *openapi_client.NewNullableString(&repoUrl),
130132
}
131-
mockClient.EXPECT().GetWorkspace(envWsId).Return(ws, nil)
133+
mockEnv.EXPECT().GetWorkspaceId().Return(wsId, nil)
134+
mockClient.EXPECT().GetWorkspace(99).Return(ws, nil)
132135
mockGit.EXPECT().CloneRepository(memoryFs, repoUrl, branch, clonedir).Return(nil, nil)
133136

134137
err := cmd.CloneRepository(mockClient, memoryFs, mockGit, clonedir)
@@ -144,7 +147,7 @@ var _ = Describe("GenerateDocker", func() {
144147
GenerateOpts: &cmd.GenerateOpts{
145148
GlobalOptions: cmd.GlobalOptions{
146149
Env: mockEnv,
147-
WorkspaceId: &flagWsId,
150+
WorkspaceId: flagWsId,
148151
},
149152
},
150153
BaseImage: "alpine:latest",

cli/cmd/generate_images_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var _ = Describe("GenerateImages", func() {
4242
GenerateOpts: &cmd.GenerateOpts{
4343
GlobalOptions: cmd.GlobalOptions{
4444
Env: mockEnv,
45-
WorkspaceId: &wsId,
45+
WorkspaceId: wsId,
4646
},
4747
Input: defaultInput,
4848
Output: defaultOutput,

cli/cmd/generate_kubernetes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var _ = Describe("GenerateKubernetes", func() {
4040
GenerateOpts: &cmd.GenerateOpts{
4141
GlobalOptions: cmd.GlobalOptions{
4242
Env: mockEnv,
43-
WorkspaceId: &wsId,
43+
WorkspaceId: wsId,
4444
},
4545
Input: defaultInput,
4646
Output: defaultOutput,

cli/cmd/list_workspaces.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cmd
55

66
import (
77
"fmt"
8+
"log"
89

910
"github.com/codesphere-cloud/cs-go/api"
1011
"github.com/codesphere-cloud/cs-go/pkg/io"
@@ -80,14 +81,9 @@ func (l *ListWorkspacesCmd) ListWorkspaces(client Client) ([]api.Workspace, erro
8081
}
8182

8283
func (l *ListWorkspacesCmd) getTeamIds(client Client) (teams []int, err error) {
83-
if l.Opts.TeamId != nil && *l.Opts.TeamId >= 0 {
84-
teams = append(teams, *l.Opts.TeamId)
85-
return
86-
}
87-
teamIdEnv, err := l.Opts.Env.GetTeamId()
84+
teamIdEnv, err := l.Opts.GetTeamId()
8885
if err != nil {
89-
err = fmt.Errorf("failed to get team ID from env: %w", err)
90-
return
86+
log.Println("No team ID provided via flag or environment variable, listing workspaces of all teams")
9187
}
9288
if teamIdEnv >= 0 {
9389
teams = append(teams, teamIdEnv)

0 commit comments

Comments
 (0)