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

feat: Option to list all workspaces #416

Merged
merged 5 commits into from
Aug 12, 2021
Merged

Conversation

goodspark
Copy link
Contributor

From an admin POV, this will be helpful for various reasons.

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) },
Copy link
Contributor Author

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?

Copy link
Member

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.

}
if provider != "" {
if provider != "" || all {
Copy link
Member

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

Copy link
Contributor Author

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.

@deansheather
Copy link
Member

This looks great, just needs a few changes and it'll be solid 😄

@goodspark goodspark changed the title Option to list all workspaces feat: Option to list all workspaces Aug 12, 2021
Comment on lines 96 to 108
} 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
}
}
Copy link
Contributor Author

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.

@goodspark goodspark requested a review from deansheather August 12, 2021 16:21
Copy link
Member

@deansheather deansheather left a 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

if provider != "" {
var workspaces []coder.Workspace
if all {
var err error
Copy link
Member

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

@cdrci cdrci merged commit cf9e7e4 into coder:master Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants