MCPcopy Create free account
hub / github.com/cli/cli / newCreateCmd

Function newCreateCmd

pkg/cmd/codespace/create.go:84–126  ·  view source on GitHub ↗
(app *App)

Source from the content-addressed store, hash-verified

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

Callers 2

TestCreateCmdFlagErrorFunction · 0.85
NewCmdCodespaceFunction · 0.85

Calls 5

FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
validateNWOFunction · 0.85
CreateMethod · 0.65

Tested by 1

TestCreateCmdFlagErrorFunction · 0.68