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

Remove --user flag from "envs create" #203

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/coder_envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Perform operations on the Coder environments owned by the active user.
### Options

```
-h, --help help for envs
--user string Specify the user whose resources to target (default "me")
-h, --help help for envs
```

### Options inherited from parent commands
Expand Down
3 changes: 1 addition & 2 deletions docs/coder_envs_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions docs/coder_envs_edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ coder envs edit back-end-env --disk 20
--not-container-vm do not deploy the environment as a Container-based VM
-o, --org string name of the organization the environment should be created under.
-t, --tag string image tag of the image you want to base the environment off of. (default "latest")
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions docs/coder_envs_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ coder envs ls [flags]
```
-h, --help help for ls
-o, --output string human | json (default "human")
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
10 changes: 5 additions & 5 deletions docs/coder_envs_rebuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ coder envs rebuild backend-env --force
### Options

```
--follow follow build log after initiating rebuild
--force force rebuild without showing a confirmation prompt
-h, --help help for rebuild
--follow follow build log after initiating rebuild
--force force rebuild without showing a confirmation prompt
-h, --help help for rebuild
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
8 changes: 4 additions & 4 deletions docs/coder_envs_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ coder envs rm [...environment_names] [flags]
### Options

```
-f, --force force remove the specified environments without prompting first
-h, --help help for rm
-f, --force force remove the specified environments without prompting first
-h, --help help for rm
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
6 changes: 3 additions & 3 deletions docs/coder_envs_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ coder envs --user charlie@coder.com ls -o json \
### Options

```
-h, --help help for stop
-h, --help help for stop
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
6 changes: 3 additions & 3 deletions docs/coder_envs_watch-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ coder envs watch-build front-end-env
### Options

```
-h, --help help for watch-build
-h, --help help for watch-build
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
64 changes: 38 additions & 26 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ import (
const defaultImgTag = "latest"

func envsCmd() *cobra.Command {
var user string
cmd := &cobra.Command{
Use: "envs",
Short: "Interact with Coder environments",
Long: "Perform operations on the Coder environments owned by the active user.",
}
cmd.PersistentFlags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")

cmd.AddCommand(
lsEnvsCommand(&user),
stopEnvsCmd(&user),
rmEnvsCmd(&user),
watchBuildLogCommand(&user),
rebuildEnvCommand(&user),
createEnvCmd(&user),
editEnvCmd(&user),
lsEnvsCommand(),
stopEnvsCmd(),
rmEnvsCmd(),
watchBuildLogCommand(),
rebuildEnvCommand(),
createEnvCmd(),
editEnvCmd(),
)
return cmd
}
Expand All @@ -43,8 +41,11 @@ const (
jsonOutput = "json"
)

func lsEnvsCommand(user *string) *cobra.Command {
var outputFmt string
func lsEnvsCommand() *cobra.Command {
var (
outputFmt string
user string
)

cmd := &cobra.Command{
Use: "ls",
Expand All @@ -56,7 +57,7 @@ func lsEnvsCommand(user *string) *cobra.Command {
if err != nil {
return err
}
envs, err := getEnvs(ctx, client, *user)
envs, err := getEnvs(ctx, client, user)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,13 +86,15 @@ func lsEnvsCommand(user *string) *cobra.Command {
},
}

cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
cmd.Flags().StringVarP(&outputFmt, "output", "o", humanOutput, "human | json")

return cmd
}

func stopEnvsCmd(user *string) *cobra.Command {
return &cobra.Command{
func stopEnvsCmd() *cobra.Command {
var user string
cmd := &cobra.Command{
Use: "stop [...environment_names]",
Short: "stop Coder environments by name",
Long: "Stop Coder environments by name",
Expand All @@ -117,7 +120,7 @@ coder envs --user charlie@coder.com ls -o json \
for _, envName := range args {
envName := envName
egroup.Go(func() error {
env, err := findEnv(ctx, client, envName, *user)
env, err := findEnv(ctx, client, envName, user)
if err != nil {
return err
}
Expand All @@ -136,9 +139,11 @@ coder envs --user charlie@coder.com ls -o json \
return egroup.Wait()
},
}
cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
return cmd
}

func createEnvCmd(user *string) *cobra.Command {
func createEnvCmd() *cobra.Command {
var (
org string
cpu float32
Expand Down Expand Up @@ -170,7 +175,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
return err
}

multiOrgMember, err := isMultiOrgMember(ctx, client, *user)
multiOrgMember, err := isMultiOrgMember(ctx, client, coder.Me)
if err != nil {
return err
}
Expand All @@ -180,7 +185,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
}

importedImg, err := findImg(ctx, client, findImgConf{
email: *user,
email: coder.Me,
imgName: img,
orgName: org,
})
Expand Down Expand Up @@ -245,7 +250,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
return cmd
}

func editEnvCmd(user *string) *cobra.Command {
func editEnvCmd() *cobra.Command {
var (
org string
img string
Expand All @@ -257,6 +262,7 @@ func editEnvCmd(user *string) *cobra.Command {
follow bool
useCVM bool
notCVM bool
user string
)

cmd := &cobra.Command{
Expand All @@ -276,12 +282,12 @@ coder envs edit back-end-env --disk 20`,

envName := args[0]

env, err := findEnv(ctx, client, envName, *user)
env, err := findEnv(ctx, client, envName, user)
if err != nil {
return err
}

multiOrgMember, err := isMultiOrgMember(ctx, client, *user)
multiOrgMember, err := isMultiOrgMember(ctx, client, user)
if err != nil {
return err
}
Expand Down Expand Up @@ -337,11 +343,16 @@ coder envs edit back-end-env --disk 20`,
cmd.Flags().BoolVar(&follow, "follow", false, "follow buildlog after initiating rebuild")
cmd.Flags().BoolVar(&useCVM, "container-vm", false, "deploy the environment as a Container-based VM")
cmd.Flags().BoolVar(&notCVM, "not-container-vm", false, "do not deploy the environment as a Container-based VM")
cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
return cmd
}

func rmEnvsCmd(user *string) *cobra.Command {
var force bool
func rmEnvsCmd() *cobra.Command {
var (
force bool
user string
)

cmd := &cobra.Command{
Use: "rm [...environment_names]",
Short: "remove Coder environments by name",
Expand Down Expand Up @@ -369,7 +380,7 @@ func rmEnvsCmd(user *string) *cobra.Command {
for _, envName := range args {
envName := envName
egroup.Go(func() error {
env, err := findEnv(ctx, client, envName, *user)
env, err := findEnv(ctx, client, envName, user)
if err != nil {
return err
}
Expand All @@ -387,6 +398,7 @@ func rmEnvsCmd(user *string) *cobra.Command {
},
}
cmd.Flags().BoolVarP(&force, "force", "f", false, "force remove the specified environments without prompting first")
cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
return cmd
}

Expand All @@ -396,7 +408,7 @@ type updateConf struct {
diskGB int
gpus int
environment *coder.Environment
user *string
user string
image string
imageTag string
orgName string
Expand Down Expand Up @@ -427,7 +439,7 @@ func buildUpdateReq(ctx context.Context, client *coder.Client, conf updateConf)
// If this is not empty it means the user is requesting to change the environment image.
if conf.image != "" {
importedImg, err := findImg(ctx, client, findImgConf{
email: *conf.user,
email: conf.user,
imgName: conf.image,
orgName: conf.orgName,
})
Expand Down
12 changes: 8 additions & 4 deletions internal/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
"golang.org/x/xerrors"
)

func rebuildEnvCommand(user *string) *cobra.Command {
func rebuildEnvCommand() *cobra.Command {
var follow bool
var force bool
var user string
cmd := &cobra.Command{
Use: "rebuild [environment_name]",
Short: "rebuild a Coder environment",
Expand All @@ -32,7 +33,7 @@ coder envs rebuild backend-env --force`,
if err != nil {
return err
}
env, err := findEnv(ctx, client, args[0], *user)
env, err := findEnv(ctx, client, args[0], user)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,6 +68,7 @@ coder envs rebuild backend-env --force`,
},
}

cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
cmd.Flags().BoolVar(&follow, "follow", false, "follow build log after initiating rebuild")
cmd.Flags().BoolVar(&force, "force", false, "force rebuild without showing a confirmation prompt")
return cmd
Expand Down Expand Up @@ -136,7 +138,8 @@ func trailBuildLogs(ctx context.Context, client *coder.Client, envID string) err
return nil
}

func watchBuildLogCommand(user *string) *cobra.Command {
func watchBuildLogCommand() *cobra.Command {
var user string
cmd := &cobra.Command{
Use: "watch-build [environment_name]",
Example: "coder envs watch-build front-end-env",
Expand All @@ -148,7 +151,7 @@ func watchBuildLogCommand(user *string) *cobra.Command {
if err != nil {
return err
}
env, err := findEnv(ctx, client, args[0], *user)
env, err := findEnv(ctx, client, args[0], user)
if err != nil {
return err
}
Expand All @@ -159,5 +162,6 @@ func watchBuildLogCommand(user *string) *cobra.Command {
return nil
},
}
cmd.Flags().StringVar(&user, "user", coder.Me, "Specify the user whose resources to target")
return cmd
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy