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

Function newCreateCmd

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

Source from the content-addressed store, hash-verified

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