diff --git a/internal/codespaces/api/api.go b/internal/codespaces/api/api.go index 8de16bbb8..ed86a2c6c 100644 --- a/internal/codespaces/api/api.go +++ b/internal/codespaces/api/api.go @@ -481,6 +481,7 @@ type CreateCodespaceParams struct { Branch string Machine string Location string + DevContainerPath string } // CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it @@ -526,6 +527,7 @@ type startCreateRequest struct { Ref string `json:"ref"` Location string `json:"location"` Machine string `json:"machine"` + DevContainerPath string `json:"devcontainer_path,omitempty"` } var errProvisioningInProgress = errors.New("provisioning in progress") @@ -545,6 +547,7 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (* Ref: params.Branch, Location: params.Location, Machine: params.Machine, + DevContainerPath: params.DevContainerPath, }) if err != nil { return nil, fmt.Errorf("error marshaling request: %w", err) diff --git a/pkg/cmd/codespace/create.go b/pkg/cmd/codespace/create.go index ee9d81fe7..8f884f8da 100644 --- a/pkg/cmd/codespace/create.go +++ b/pkg/cmd/codespace/create.go @@ -13,11 +13,12 @@ import ( ) type createOptions struct { - repo string - branch string - machine string - showStatus bool - idleTimeout time.Duration + repo string + branch string + machine string + showStatus bool + idleTimeout time.Duration + devContainerPath string } func newCreateCmd(app *App) *cobra.Command { @@ -37,6 +38,7 @@ func newCreateCmd(app *App) *cobra.Command { createCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "hardware specifications for the VM") createCmd.Flags().BoolVarP(&opts.showStatus, "status", "s", false, "show status of post-create command and dotfiles") createCmd.Flags().DurationVar(&opts.idleTimeout, "idle-timeout", 0, "allowed inactivity before codespace is stopped, e.g. \"10m\", \"1h\"") + createCmd.Flags().StringVar(&opts.devContainerPath, "devcontainer-path", "", "path to the devcontainer.json file to use when creating codespace") return createCmd } @@ -109,6 +111,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { Machine: machine, Location: locationResult.Location, IdleTimeoutMinutes: int(opts.idleTimeout.Minutes()), + DevContainerPath: opts.devContainerPath, }) a.StopProgressIndicator() if err != nil { diff --git a/pkg/cmd/codespace/create_test.go b/pkg/cmd/codespace/create_test.go index 4b266ffaa..c5c1ea075 100644 --- a/pkg/cmd/codespace/create_test.go +++ b/pkg/cmd/codespace/create_test.go @@ -51,6 +51,9 @@ func TestApp_Create(t *testing.T) { if params.IdleTimeoutMinutes != 30 { return nil, fmt.Errorf("idle timeout minutes was %v", params.IdleTimeoutMinutes) } + if params.DevContainerPath != ".devcontainer/foobar/devcontainer.json" { + return nil, fmt.Errorf("got dev container path %q, want %q", params.DevContainerPath, ".devcontainer/foobar/devcontainer.json") + } return &api.Codespace{ Name: "monalisa-dotfiles-abcd1234", }, nil @@ -58,11 +61,12 @@ func TestApp_Create(t *testing.T) { }, }, opts: createOptions{ - repo: "monalisa/dotfiles", - branch: "", - machine: "GIGA", - showStatus: false, - idleTimeout: 30 * time.Minute, + repo: "monalisa/dotfiles", + branch: "", + machine: "GIGA", + showStatus: false, + idleTimeout: 30 * time.Minute, + devContainerPath: ".devcontainer/foobar/devcontainer.json", }, wantStdout: "monalisa-dotfiles-abcd1234\n", },