| 17 | } |
| 18 | |
| 19 | func newEditCmd(app *App) *cobra.Command { |
| 20 | opts := editOptions{} |
| 21 | |
| 22 | editCmd := &cobra.Command{ |
| 23 | Use: "edit", |
| 24 | Short: "Edit a codespace", |
| 25 | Args: noArgsConstraint, |
| 26 | RunE: func(cmd *cobra.Command, args []string) error { |
| 27 | if opts.displayName == "" && opts.machine == "" { |
| 28 | return cmdutil.FlagErrorf("must provide `--display-name` or `--machine`") |
| 29 | } |
| 30 | |
| 31 | return app.Edit(cmd.Context(), opts) |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | opts.selector = AddCodespaceSelector(editCmd, app.apiClient) |
| 36 | editCmd.Flags().StringVarP(&opts.displayName, "display-name", "d", "", "Set the display name") |
| 37 | editCmd.Flags().StringVar(&opts.displayName, "displayName", "", "Display name") |
| 38 | if err := editCmd.Flags().MarkDeprecated("displayName", "use `--display-name` instead"); err != nil { |
| 39 | fmt.Fprintf(app.io.ErrOut, "error marking flag as deprecated: %v\n", err) |
| 40 | } |
| 41 | editCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "Set hardware specifications for the VM") |
| 42 | |
| 43 | return editCmd |
| 44 | } |
| 45 | |
| 46 | // Edits a codespace |
| 47 | func (a *App) Edit(ctx context.Context, opts editOptions) error { |