Skip to content

Commit 89d667c

Browse files
committed
fixed json/yaml for list
1 parent ad23399 commit 89d667c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

internal/cmd/beta/logs/access_token/list/list.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,12 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7272
return fmt.Errorf("list access tokens: %w", err)
7373
}
7474

75-
if resp.Tokens == nil || len(*resp.Tokens) == 0 {
76-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
77-
if err != nil {
78-
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
79-
projectLabel = model.ProjectId
80-
} else if projectLabel == "" {
81-
projectLabel = model.ProjectId
82-
}
83-
params.Printer.Outputf("No access token found for project %q\n", projectLabel)
84-
return nil
75+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
76+
if err != nil {
77+
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
78+
projectLabel = model.ProjectId
79+
} else if projectLabel == "" {
80+
projectLabel = model.ProjectId
8581
}
8682

8783
// Truncate output
@@ -90,7 +86,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9086
items = items[:*model.Limit]
9187
}
9288

93-
return outputResult(params.Printer, model.OutputFormat, items)
89+
return outputResult(params.Printer, model.OutputFormat, items, projectLabel)
9490
},
9591
}
9692
configureFlags(cmd)
@@ -133,8 +129,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logs.APICli
133129
return apiClient.ListAccessTokens(ctx, model.ProjectId, model.Region, model.InstanceId)
134130
}
135131

136-
func outputResult(p *print.Printer, outputFormat string, tokens []logs.AccessToken) error {
132+
func outputResult(p *print.Printer, outputFormat string, tokens []logs.AccessToken, projectLabel string) error {
137133
return p.OutputResult(outputFormat, tokens, func() error {
134+
if len(tokens) == 0 {
135+
p.Outputf("No access token found for project %q\n", projectLabel)
136+
return nil
137+
}
138+
138139
table := tables.NewTable()
139140
table.SetHeader("ID", "NAME", "DESCRIPTION", "PERMISSIONS", "VALID UNTIL", "STATUS")
140141

internal/cmd/beta/logs/access_token/list/list_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func TestOutputResult(t *testing.T) {
186186
type args struct {
187187
outputFormat string
188188
accessTokens []logs.AccessToken
189+
projectLabel string
189190
}
190191
tests := []struct {
191192
name string
@@ -231,7 +232,7 @@ func TestOutputResult(t *testing.T) {
231232
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
232233
for _, tt := range tests {
233234
t.Run(tt.name, func(t *testing.T) {
234-
if err := outputResult(p, tt.args.outputFormat, tt.args.accessTokens); (err != nil) != tt.wantErr {
235+
if err := outputResult(p, tt.args.outputFormat, tt.args.accessTokens, tt.args.projectLabel); (err != nil) != tt.wantErr {
235236
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
236237
}
237238
})

0 commit comments

Comments
 (0)