| 81 | } |
| 82 | |
| 83 | func newCreateCmd(app *App) *cobra.Command { |
| 84 | opts := createOptions{} |
| 85 | |
| 86 | createCmd := &cobra.Command{ |
| 87 | Use: "create", |
| 88 | Short: "Create a codespace", |
| 89 | Args: noArgsConstraint, |
| 90 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 91 | return cmdutil.MutuallyExclusive( |
| 92 | "using --web with --display-name, --idle-timeout, or --retention-period is not supported", |
| 93 | opts.useWeb, |
| 94 | opts.displayName != "" || opts.idleTimeout != 0 || opts.retentionPeriod.Duration != nil, |
| 95 | ) |
| 96 | }, |
| 97 | RunE: func(cmd *cobra.Command, args []string) error { |
| 98 | return app.Create(cmd.Context(), opts) |
| 99 | }, |
| 100 | } |
| 101 | |
| 102 | createCmd.Flags().BoolVarP(&opts.useWeb, "web", "w", false, "Create codespace from browser, cannot be used with --display-name, --idle-timeout, or --retention-period") |
| 103 | |
| 104 | createCmd.Flags().StringVarP(&opts.repo, "repo", "R", "", "Repository name with owner: user/repo") |
| 105 | if err := addDeprecatedRepoShorthand(createCmd, &opts.repo); err != nil { |
| 106 | fmt.Fprintf(app.io.ErrOut, "%v\n", err) |
| 107 | } |
| 108 | |
| 109 | createCmd.Flags().StringVarP(&opts.branch, "branch", "b", "", "Repository branch") |
| 110 | createCmd.Flags().StringVarP(&opts.location, "location", "l", "", "Location: {EastUs|SouthEastAsia|WestEurope|WestUs2} (determined automatically if not provided)") |
| 111 | createCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "Hardware specifications for the VM") |
| 112 | createCmd.Flags().BoolVarP(&opts.permissionsOptOut, "default-permissions", "", false, "Do not prompt to accept additional permissions requested by the codespace") |
| 113 | createCmd.Flags().BoolVarP(&opts.showStatus, "status", "s", false, "Show status of post-create command and dotfiles") |
| 114 | createCmd.Flags().DurationVar(&opts.idleTimeout, "idle-timeout", 0, "Allowed inactivity before codespace is stopped, e.g. \"10m\", \"1h\"") |
| 115 | createCmd.Flags().Var(&opts.retentionPeriod, "retention-period", "Allowed time after shutting down before the codespace is automatically deleted (maximum 30 days), e.g. \"1h\", \"72h\"") |
| 116 | createCmd.Flags().StringVar(&opts.devContainerPath, "devcontainer-path", "", "Path to the devcontainer.json file to use when creating codespace") |
| 117 | createCmd.Flags().StringVarP(&opts.displayName, "display-name", "d", "", fmt.Sprintf("Display name for the codespace (%d characters or less)", displayNameMaxLength)) |
| 118 | |
| 119 | return createCmd |
| 120 | } |
| 121 | |
| 122 | // Create creates a new Codespace |
| 123 | func (a *App) Create(ctx context.Context, opts createOptions) error { |