Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[env] add project filter to ls command #382

Merged
merged 4 commits into from
Sep 10, 2024
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ CHANGELOG
- Add command to clone environments.
[#376](https://github.com/pulumi/esc/pull/376)

- Add project filter flag to env ls command.
[#382](https://github.com/pulumi/esc/pull/382)

## 0.9.2

- Add commands to manage environment tags.
Expand Down
2 changes: 1 addition & 1 deletion cmd/esc/cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (cmd *envCommand) getNewEnvRef(
}

// Check if project at <org-name>/<project-name> exists. Assume not if listing environments errors
allEnvs, _ := cmd.listEnvironments(ctx, "")
allEnvs, _ := cmd.listEnvironments(ctx, "", "")
existsProject := false
for _, e := range allEnvs {
if strings.EqualFold(e.Project, ref.projectName) {
Expand Down
16 changes: 12 additions & 4 deletions cmd/esc/cli/env_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
)

func newEnvLsCmd(env *envCommand) *cobra.Command {
var orgFilter string
var (
orgFilter string
projectFilter string
)

cmd := &cobra.Command{
Use: "ls",
Expand All @@ -30,7 +33,7 @@ func newEnvLsCmd(env *envCommand) *cobra.Command {
return err
}

allEnvs, err := env.listEnvironments(ctx, orgFilter)
allEnvs, err := env.listEnvironments(ctx, orgFilter, projectFilter)
if err != nil {
return err
}
Expand All @@ -55,12 +58,14 @@ func newEnvLsCmd(env *envCommand) *cobra.Command {
}

cmd.PersistentFlags().StringVarP(
&orgFilter, "organization", "o", "", "Filter returned stacks to those in a specific organization")
&orgFilter, "organization", "o", "", "Filter returned environments to those in a specific organization")
cmd.PersistentFlags().StringVarP(
&projectFilter, "project", "p", "", "Filter returned environments to those in a specific project")

return cmd
}

func (env *envCommand) listEnvironments(ctx context.Context, orgFilter string) ([]client.OrgEnvironment, error) {
func (env *envCommand) listEnvironments(ctx context.Context, orgFilter, projectFilter string) ([]client.OrgEnvironment, error) {
user := env.esc.account.Username
continuationToken, allEnvs := "", []client.OrgEnvironment(nil)
for {
Expand All @@ -72,6 +77,9 @@ func (env *envCommand) listEnvironments(ctx context.Context, orgFilter string) (
if e.Organization == user {
e.Organization = ""
}
if projectFilter != "" && e.Project != projectFilter {
continue
}
allEnvs = append(allEnvs, e)
}
if nextToken == "" {
Expand Down
Loading