Add devcontainer_path API param as an option

This commit is contained in:
Jeff Hubbard 2022-01-21 10:20:15 -08:00
parent 2e07d0f32c
commit e7f888ad1d
3 changed files with 20 additions and 10 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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",
},