MCPcopy Index your code
hub / github.com/coder/coder / Create

Method Create

cli/create.go:36–470  ·  view source on GitHub ↗
(opts CreateOptions)

Source from the content-addressed store, hash-verified

34}
35
36func (r *RootCmd) Create(opts CreateOptions) *serpent.Command {
37 var (
38 templateName string
39 templateVersion string
40 presetName string
41 startAt string
42 stopAfter time.Duration
43 workspaceName string
44
45 parameterFlags workspaceParameterFlags
46 autoUpdates string
47 copyParametersFrom string
48 noWait bool
49 // Organization context is only required if more than 1 template
50 // shares the same name across multiple organizations.
51 orgContext = NewOrganizationContext()
52 )
53 cmd := &serpent.Command{
54 Annotations: workspaceCommand,
55 Use: "create [workspace]",
56 Short: "Create a workspace",
57 Long: FormatExamples(
58 Example{
59 Description: "Create a workspace for another user (if you have permission)",
60 Command: "coder create <username>/<workspace_name>",
61 },
62 ),
63 Handler: func(inv *serpent.Invocation) error {
64 client, err := r.InitClient(inv)
65 if err != nil {
66 return err
67 }
68
69 workspaceOwner := codersdk.Me
70 if len(inv.Args) >= 1 {
71 workspaceOwner, workspaceName, err = codersdk.SplitWorkspaceIdentifier(inv.Args[0])
72 if err != nil {
73 return err
74 }
75 }
76
77 if workspaceName == "" {
78 workspaceName, err = cliui.Prompt(inv, cliui.PromptOptions{
79 Text: "Specify a name for your workspace:",
80 Validate: func(workspaceName string) error {
81 err = codersdk.NameValid(workspaceName)
82 if err != nil {
83 return xerrors.Errorf("workspace name %q is invalid: %w", workspaceName, err)
84 }
85 _, err = client.WorkspaceByOwnerAndName(inv.Context(), workspaceOwner, workspaceName, codersdk.WorkspaceOptions{})
86 if err == nil {
87 return xerrors.Errorf("a workspace already exists named %q", workspaceName)
88 }
89 return nil
90 },
91 })
92 if err != nil {
93 return err

Callers 2

CoreSubcommandsMethod · 0.95

Calls 15

InitClientMethod · 0.95
SplitWorkspaceIdentifierFunction · 0.92
PromptFunction · 0.92
NameValidFunction · 0.92
DescendingFunction · 0.92
PlaceholderFunction · 0.92
SelectFunction · 0.92
RefFunction · 0.92
BoldFunction · 0.92
AutomaticUpdatesTypeAlias · 0.92
WarnMatchedProvisionersFunction · 0.92
KeywordFunction · 0.92

Tested by

no test coverage detected