Skip to content

Commit a6e4a5a

Browse files
authored
fix: pass GlobalOptions as pointer (#195)
1 parent 2c3e524 commit a6e4a5a

37 files changed

+84
-84
lines changed

cli/cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type CreateCmd struct {
1111
cmd *cobra.Command
1212
}
1313

14-
func AddCreateCmd(rootCmd *cobra.Command, opts GlobalOptions) {
14+
func AddCreateCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
1515
create := CreateCmd{
1616
cmd: &cobra.Command{
1717
Use: "create",

cli/cmd/create_workspace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type CreateWorkspaceCmd struct {
2424
}
2525

2626
type CreateWorkspaceOpts struct {
27-
GlobalOptions
27+
*GlobalOptions
2828
Repo *string
2929
Vpn *string
3030
Env *[]string
@@ -37,7 +37,7 @@ type CreateWorkspaceOpts struct {
3737
}
3838

3939
func (c *CreateWorkspaceCmd) RunE(_ *cobra.Command, args []string) error {
40-
client, err := NewClient(c.Opts.GlobalOptions)
40+
client, err := NewClient(*c.Opts.GlobalOptions)
4141
if err != nil {
4242
return fmt.Errorf("failed to create Codesphere client: %w", err)
4343
}
@@ -77,7 +77,7 @@ func (c *CreateWorkspaceCmd) RunE(_ *cobra.Command, args []string) error {
7777
return nil
7878
}
7979

80-
func AddCreateWorkspaceCmd(create *cobra.Command, opts GlobalOptions) {
80+
func AddCreateWorkspaceCmd(create *cobra.Command, opts *GlobalOptions) {
8181
workspace := CreateWorkspaceCmd{
8282
cmd: &cobra.Command{
8383
Use: "workspace",

cli/cmd/create_workspace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var _ = Describe("CreateWorkspace", func() {
5454
teamId = 21
5555
c = &cmd.CreateWorkspaceCmd{
5656
Opts: cmd.CreateWorkspaceOpts{
57-
GlobalOptions: cmd.GlobalOptions{
57+
GlobalOptions: &cmd.GlobalOptions{
5858
Env: mockEnv,
5959
TeamId: teamId,
6060
},
@@ -98,7 +98,7 @@ var _ = Describe("CreateWorkspace", func() {
9898
createCmd := &cobra.Command{Use: "create"}
9999
opts := &cmd.GlobalOptions{Env: cs.NewEnv()}
100100

101-
cmd.AddCreateWorkspaceCmd(createCmd, *opts)
101+
cmd.AddCreateWorkspaceCmd(createCmd, opts)
102102

103103
createCmd.SetArgs([]string{
104104
"workspace",

cli/cmd/curl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (e *DefaultCommandExecutor) Execute(ctx context.Context, name string, args
2727
}
2828

2929
type CurlOptions struct {
30-
GlobalOptions
30+
*GlobalOptions
3131
Timeout time.Duration
3232
Executor CommandExecutor // Injectable for testing
3333
}
@@ -38,7 +38,7 @@ type CurlCmd struct {
3838
}
3939

4040
func (c *CurlCmd) RunE(_ *cobra.Command, args []string) error {
41-
client, err := NewClient(c.Opts.GlobalOptions)
41+
client, err := NewClient(*c.Opts.GlobalOptions)
4242
if err != nil {
4343
return fmt.Errorf("failed to create Codesphere client: %w", err)
4444
}
@@ -59,7 +59,7 @@ func (c *CurlCmd) RunE(_ *cobra.Command, args []string) error {
5959
return c.CurlWorkspace(client, wsId, token, path, curlArgs)
6060
}
6161

62-
func AddCurlCmd(rootCmd *cobra.Command, opts GlobalOptions) {
62+
func AddCurlCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
6363
curl := CurlCmd{
6464
cmd: &cobra.Command{
6565
Use: "curl [path] [-- curl-args...]",

cli/cmd/curl_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var _ = Describe("Curl", func() {
4444
}
4545
c = &cmd.CurlCmd{
4646
Opts: cmd.CurlOptions{
47-
GlobalOptions: cmd.GlobalOptions{
47+
GlobalOptions: &cmd.GlobalOptions{
4848
Env: mockEnv,
4949
WorkspaceId: wsId,
5050
},

cli/cmd/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type DeleteCmd struct {
1111
cmd *cobra.Command
1212
}
1313

14-
func AddDeleteCmd(rootCmd *cobra.Command, opt GlobalOptions) {
14+
func AddDeleteCmd(rootCmd *cobra.Command, opt *GlobalOptions) {
1515
delete := DeleteCmd{
1616
cmd: &cobra.Command{
1717
Use: "delete",

cli/cmd/delete_workspace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type DeleteWorkspaceCmd struct {
2323
}
2424

2525
type DeleteWorkspaceOpts struct {
26-
GlobalOptions
26+
*GlobalOptions
2727
Confirmed *bool
2828
}
2929

@@ -33,15 +33,15 @@ func (c *DeleteWorkspaceCmd) RunE(_ *cobra.Command, args []string) error {
3333
return fmt.Errorf("failed to get workspace ID: %w", err)
3434
}
3535

36-
client, err := NewClient(c.Opts.GlobalOptions)
36+
client, err := NewClient(*c.Opts.GlobalOptions)
3737
if err != nil {
3838
return fmt.Errorf("failed to create Codesphere client: %w", err)
3939
}
4040

4141
return c.DeleteWorkspace(client, wsId)
4242
}
4343

44-
func AddDeleteWorkspaceCmd(delete *cobra.Command, opts GlobalOptions) {
44+
func AddDeleteWorkspaceCmd(delete *cobra.Command, opts *GlobalOptions) {
4545
workspace := DeleteWorkspaceCmd{
4646
cmd: &cobra.Command{
4747
Use: "workspace",

cli/cmd/delete_workspace_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("DeleteWorkspace", func() {
3131
mockPrompt = cmd.NewMockPrompt(GinkgoT())
3232
c = &cmd.DeleteWorkspaceCmd{
3333
Opts: cmd.DeleteWorkspaceOpts{
34-
GlobalOptions: cmd.GlobalOptions{
34+
GlobalOptions: &cmd.GlobalOptions{
3535
Env: mockEnv,
3636
WorkspaceId: wsId,
3737
},

cli/cmd/exec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ExecCmd struct {
2121
}
2222

2323
type ExecOptions struct {
24-
GlobalOptions
24+
*GlobalOptions
2525
EnvVar *[]string
2626
WorkDir *string
2727
}
@@ -30,15 +30,15 @@ func (c *ExecCmd) RunE(_ *cobra.Command, args []string) error {
3030
command := strings.Join(args, " ")
3131
log.Printf("running command %s\n", command)
3232

33-
client, err := NewClient(c.Opts.GlobalOptions)
33+
client, err := NewClient(*c.Opts.GlobalOptions)
3434
if err != nil {
3535
return fmt.Errorf("failed to create Codesphere client: %w", err)
3636
}
3737

3838
return c.ExecCommand(client, command)
3939
}
4040

41-
func AddExecCmd(rootCmd *cobra.Command, opts GlobalOptions) {
41+
func AddExecCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
4242
exec := ExecCmd{
4343
cmd: &cobra.Command{
4444
Use: "exec",

cli/cmd/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var _ = Describe("Exec", func() {
3232
JustBeforeEach(func() {
3333
e = &cmd.ExecCmd{
3434
Opts: cmd.ExecOptions{
35-
GlobalOptions: cmd.GlobalOptions{
35+
GlobalOptions: &cmd.GlobalOptions{
3636
Env: mockEnv,
3737
WorkspaceId: wsId,
3838
},

0 commit comments

Comments
 (0)