Skip to content

Commit 6e2390a

Browse files
committed
lifecyce state flag
Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
1 parent c62aaaa commit 6e2390a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

internal/cmd/project/list/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
const (
3131
parentIdFlag = "parent-id"
32+
lifecycleStateFlag = "lifecycle-state"
3233
projectIdLikeFlag = "project-id-like"
3334
memberFlag = "member"
3435
creationTimeAfterFlag = "creation-time-after"
@@ -47,6 +48,7 @@ type inputModel struct {
4748
CreationTimeAfter *time.Time
4849
Limit *int64
4950
PageSize int64
51+
LifecycleState string
5052
}
5153

5254
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -104,6 +106,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
104106
}
105107

106108
func configureFlags(cmd *cobra.Command) {
109+
cmd.Flags().String(lifecycleStateFlag, "active", "Filter by lifecycle state")
107110
cmd.Flags().String(parentIdFlag, "", "Filter by parent identifier")
108111
cmd.Flags().Var(flags.UUIDSliceFlag(), projectIdLikeFlag, "Filter by project identifier. Multiple project IDs can be provided, but they need to belong to the same parent resource")
109112
cmd.Flags().String(memberFlag, "", "Filter by member. The list of projects of which the member is part of will be shown")
@@ -147,6 +150,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
147150
CreationTimeAfter: creationTimeAfter,
148151
Limit: limit,
149152
PageSize: pageSize,
153+
LifecycleState: flags.FlagWithDefaultToStringValue(p, cmd, lifecycleStateFlag),
150154
}
151155

152156
p.DebugInputModel(model)

internal/cmd/project/list/tree.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package list
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"sync"
78

89
"golang.org/x/sync/errgroup"
@@ -38,7 +39,10 @@ type resourceTree struct {
3839
authClient *authorization.APIClient
3940
resourceClient *resourcemanager.APIClient
4041
member string
41-
roots map[string]*node
42+
43+
projectLifecycleState *string
44+
45+
roots map[string]*node
4246
}
4347

4448
func newResourceTree(resourceClient *resourcemanager.APIClient, authClient *authorization.APIClient, model *inputModel) (*resourceTree, error) {
@@ -58,6 +62,9 @@ func newResourceTree(resourceClient *resourcemanager.APIClient, authClient *auth
5862
authClient: authClient,
5963
roots: map[string]*node{},
6064
}
65+
if model.LifecycleState != "" {
66+
tree.projectLifecycleState = &model.LifecycleState
67+
}
6168
return tree, nil
6269
}
6370

@@ -141,6 +148,9 @@ func (r *resourceTree) getNodeProjects(ctx context.Context, parent *node) error
141148
}
142149
}
143150
for _, proj := range resp.GetItems() {
151+
if r.projectLifecycleState != nil && *r.projectLifecycleState != strings.ToLower(string(proj.GetLifecycleState())) {
152+
continue
153+
}
144154
projNode := &node{
145155
resourceID: proj.GetProjectId(),
146156
typ: resourceTypeProject,

0 commit comments

Comments
 (0)