forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.go
More file actions
64 lines (55 loc) · 1.7 KB
/
edit.go
File metadata and controls
64 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package codespace
import (
"context"
"fmt"
"time"
"github.com/cli/cli/v2/internal/codespaces/api"
"github.com/spf13/cobra"
)
type editOptions struct {
codespaceName string
displayName string
idleTimeout time.Duration
machine string
}
func newEditCmd(app *App) *cobra.Command {
opts := editOptions{}
editCmd := &cobra.Command{
Use: "edit",
Short: "Edit a codespace",
Args: noArgsConstraint,
RunE: func(cmd *cobra.Command, args []string) error {
return app.Edit(cmd.Context(), opts)
},
}
editCmd.Flags().StringVarP(&opts.codespaceName, "codespace", "c", "", "Name of the codespace")
editCmd.Flags().StringVarP(&opts.displayName, "displayName", "d", "", "display name")
editCmd.Flags().DurationVar(&opts.idleTimeout, "idle-timeout", 0, "allowed inactivity before codespace is stopped, e.g. \"10m\", \"1h\"")
editCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "hardware specifications for the VM")
return editCmd
}
// Edits a codespace
func (a *App) Edit(ctx context.Context, opts editOptions) error {
userInputs := struct {
CodespaceName string
DisplayName string
IdleTimeout time.Duration
SKU string
}{
CodespaceName: opts.codespaceName,
DisplayName: opts.displayName,
IdleTimeout: opts.idleTimeout,
SKU: opts.machine,
}
a.StartProgressIndicatorWithLabel("Editing codespace")
_, err := a.apiClient.EditCodespace(ctx, userInputs.CodespaceName, &api.EditCodespaceParams{
DisplayName: userInputs.DisplayName,
IdleTimeoutMinutes: int(userInputs.IdleTimeout.Minutes()),
Machine: userInputs.SKU,
})
a.StopProgressIndicator()
if err != nil {
return fmt.Errorf("error editing codespace: %w", err)
}
return nil
}