Skip to content

Commit e7f888a

Browse files
committed
Add devcontainer_path API param as an option
1 parent 2e07d0f commit e7f888a

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

internal/codespaces/api/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ type CreateCodespaceParams struct {
481481
Branch string
482482
Machine string
483483
Location string
484+
DevContainerPath string
484485
}
485486

486487
// CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it
@@ -526,6 +527,7 @@ type startCreateRequest struct {
526527
Ref string `json:"ref"`
527528
Location string `json:"location"`
528529
Machine string `json:"machine"`
530+
DevContainerPath string `json:"devcontainer_path,omitempty"`
529531
}
530532

531533
var errProvisioningInProgress = errors.New("provisioning in progress")
@@ -545,6 +547,7 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
545547
Ref: params.Branch,
546548
Location: params.Location,
547549
Machine: params.Machine,
550+
DevContainerPath: params.DevContainerPath,
548551
})
549552
if err != nil {
550553
return nil, fmt.Errorf("error marshaling request: %w", err)

pkg/cmd/codespace/create.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
)
1414

1515
type createOptions struct {
16-
repo string
17-
branch string
18-
machine string
19-
showStatus bool
20-
idleTimeout time.Duration
16+
repo string
17+
branch string
18+
machine string
19+
showStatus bool
20+
idleTimeout time.Duration
21+
devContainerPath string
2122
}
2223

2324
func newCreateCmd(app *App) *cobra.Command {
@@ -37,6 +38,7 @@ func newCreateCmd(app *App) *cobra.Command {
3738
createCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "hardware specifications for the VM")
3839
createCmd.Flags().BoolVarP(&opts.showStatus, "status", "s", false, "show status of post-create command and dotfiles")
3940
createCmd.Flags().DurationVar(&opts.idleTimeout, "idle-timeout", 0, "allowed inactivity before codespace is stopped, e.g. \"10m\", \"1h\"")
41+
createCmd.Flags().StringVar(&opts.devContainerPath, "devcontainer-path", "", "path to the devcontainer.json file to use when creating codespace")
4042

4143
return createCmd
4244
}
@@ -109,6 +111,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
109111
Machine: machine,
110112
Location: locationResult.Location,
111113
IdleTimeoutMinutes: int(opts.idleTimeout.Minutes()),
114+
DevContainerPath: opts.devContainerPath,
112115
})
113116
a.StopProgressIndicator()
114117
if err != nil {

pkg/cmd/codespace/create_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,22 @@ func TestApp_Create(t *testing.T) {
5151
if params.IdleTimeoutMinutes != 30 {
5252
return nil, fmt.Errorf("idle timeout minutes was %v", params.IdleTimeoutMinutes)
5353
}
54+
if params.DevContainerPath != ".devcontainer/foobar/devcontainer.json" {
55+
return nil, fmt.Errorf("got dev container path %q, want %q", params.DevContainerPath, ".devcontainer/foobar/devcontainer.json")
56+
}
5457
return &api.Codespace{
5558
Name: "monalisa-dotfiles-abcd1234",
5659
}, nil
5760
},
5861
},
5962
},
6063
opts: createOptions{
61-
repo: "monalisa/dotfiles",
62-
branch: "",
63-
machine: "GIGA",
64-
showStatus: false,
65-
idleTimeout: 30 * time.Minute,
64+
repo: "monalisa/dotfiles",
65+
branch: "",
66+
machine: "GIGA",
67+
showStatus: false,
68+
idleTimeout: 30 * time.Minute,
69+
devContainerPath: ".devcontainer/foobar/devcontainer.json",
6670
},
6771
wantStdout: "monalisa-dotfiles-abcd1234\n",
6872
},

0 commit comments

Comments
 (0)