-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Option to list all workspaces #416
Conversation
From an admin POV, this will be helpful for various reasons.
| { | ||
| name: "simple list", | ||
| command: []string{"workspaces", "ls", "--all"}, | ||
| assert: func(r result) { r.success(t) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity check: This isn't actually checking the output - just that the command exited with 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, yeah. This mini test framework "runs" the commands in-process and checks if the command fn returned an error.
internal/cmd/workspaces.go
Outdated
| user = "" | ||
| } | ||
| if provider != "" { | ||
| if provider != "" || all { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the --all flag only works with the --provider flag. I think that's OK for now, but it needs to be made obvious in the flag description (e.g. "requires --provider flag") and there should be a check at the top of the command to ensure --provider is set if --all is set.
$ ./coder envs ls --all
fatal: resource not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it mean it works regardless of the provider flag? If I call coder with just --all, provider is "", and the logic becomes if "" != "" || true -> if false || true -> if true. This was my intent - as an admin, I want to see all workspaces.
But looking at the actual logic/implementation for getWorkspacesByProvider, I think your point still stands. I can fix that.
|
This looks great, just needs a few changes and it'll be solid 😄 |
Co-authored-by: Dean Sheather <dean@deansheather.com>
56b570a to
e670978
Compare
internal/cmd/workspaces.go
Outdated
| } else if provider != "" { | ||
| var err error | ||
| workspaces, err = getWorkspacesByProvider(ctx, client, provider, user) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| var err error | ||
| workspaces, err = getWorkspaces(ctx, client, user) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shuffled this around because it seemed like the first fetch for the user-only workspaces was ignored if providers was also passed.
deansheather
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work well when I checked out and ran it against our deployment
internal/cmd/workspaces.go
Outdated
| if provider != "" { | ||
| var workspaces []coder.Workspace | ||
| if all { | ||
| var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need the var errs here or in the other if branches since it's already defined above, then you can condense the if err check to be underneath the if branches, so each branch is just the workspaces, err = getX() statement.
edit: check my suggestion
Co-authored-by: Dean Sheather <dean@deansheather.com>
From an admin POV, this will be helpful for various reasons.