Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 2aeb038

Browse files
authored
Removing Name from Wac templates (#303)
- Add name field to create-from-config - Add helpful error if no name provided - Let server handle repo url errors
1 parent a58a2e7 commit 2aeb038

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

internal/cmd/envs.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"io/ioutil"
10-
"net/url"
1110

1211
"cdr.dev/coder-cli/coder-sdk"
1312
"cdr.dev/coder-cli/internal/coderutil"
@@ -300,6 +299,7 @@ func createEnvFromRepoCmd() *cobra.Command {
300299
filepath string
301300
org string
302301
providerName string
302+
envName string
303303
)
304304

305305
cmd := &cobra.Command{
@@ -308,23 +308,23 @@ func createEnvFromRepoCmd() *cobra.Command {
308308
Long: "Create a new Coder environment from a config file.",
309309
Hidden: true,
310310
Example: `# create a new environment from git repository template
311-
coder envs create-from-config --repo-url github.com/cdr/m --branch my-branch
312-
coder envs create-from-config -f coder.yaml`,
311+
coder envs create-from-config --name="dev-env" --repo-url github.com/cdr/m --ref my-branch
312+
coder envs create-from-config --name="dev-env" -f coder.yaml`,
313313
RunE: func(cmd *cobra.Command, args []string) error {
314314
ctx := cmd.Context()
315315

316+
if envName == "" {
317+
return clog.Error("Must provide a environment name.",
318+
clog.BlankLine,
319+
clog.Tipf("Use --name=<env-name> to name your environment"),
320+
)
321+
}
322+
316323
client, err := newClient(ctx)
317324
if err != nil {
318325
return err
319326
}
320327

321-
if repo != "" {
322-
_, err = url.Parse(repo)
323-
if err != nil {
324-
return xerrors.Errorf("'repo' must be a valid url: %w", err)
325-
}
326-
}
327-
328328
orgs, err := getUserOrgs(ctx, client, coder.Me)
329329
if err != nil {
330330
return err
@@ -388,6 +388,7 @@ coder envs create-from-config -f coder.yaml`,
388388
TemplateID: version.TemplateID,
389389
ResourcePoolID: provider.ID,
390390
Namespace: provider.DefaultNamespace,
391+
Name: envName,
391392
})
392393
if err != nil {
393394
return handleAPIError(err)
@@ -414,6 +415,7 @@ coder envs create-from-config -f coder.yaml`,
414415
cmd.Flags().StringVarP(&repo, "repo-url", "r", "", "URL of the git repository to pull the config from. Config file must live in '.coder/coder.yaml'.")
415416
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
416417
cmd.Flags().StringVar(&providerName, "provider", "", "name of Workspace Provider with which to create the environment")
418+
cmd.Flags().StringVar(&envName, "name", "", "name of the environment to be created")
417419
return cmd
418420
}
419421

0 commit comments

Comments
 (0)