Skip to content

Commit 28af60c

Browse files
committed
Use shared CI output helpers
1 parent cf3afab commit 28af60c

3 files changed

Lines changed: 15 additions & 23 deletions

File tree

pkg/cmd/ci/secrets.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ci
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"io"
76
"os"
@@ -483,6 +482,9 @@ with an optional variant and match flags to resolve one variant.`,
483482
depot ci secrets get MY_API_KEY production --output json`,
484483
Args: cobra.MaximumNArgs(2),
485484
RunE: func(cmd *cobra.Command, args []string) error {
485+
if err := validateTextOrJSONOutput(output); err != nil {
486+
return err
487+
}
486488
ctx := cmd.Context()
487489

488490
if orgID == "" {
@@ -534,10 +536,8 @@ with an optional variant and match flags to resolve one variant.`,
534536
resolved = matches[0]
535537
}
536538

537-
if output == "json" {
538-
enc := json.NewEncoder(os.Stdout)
539-
enc.SetIndent("", " ")
540-
return enc.Encode(resolved)
539+
if outputIsJSON(output) {
540+
return writeJSON(resolved)
541541
}
542542

543543
printSecretVariantDetail(secretName, resolved)
@@ -621,6 +621,9 @@ attributes. Passing a secret name lists one grouped secret.`,
621621
Aliases: []string{"ls"},
622622
Args: cobra.MaximumNArgs(1),
623623
RunE: func(cmd *cobra.Command, args []string) error {
624+
if err := validateTextOrJSONOutput(output); err != nil {
625+
return err
626+
}
624627
ctx := cmd.Context()
625628

626629
if orgID == "" {
@@ -657,10 +660,8 @@ attributes. Passing a secret name lists one grouped secret.`,
657660
}
658661
}
659662

660-
if output == "json" {
661-
enc := json.NewEncoder(os.Stdout)
662-
enc.SetIndent("", " ")
663-
return enc.Encode(result)
663+
if outputIsJSON(output) {
664+
return writeJSON(result)
664665
}
665666

666667
if len(result.Secrets) == 0 {

pkg/cmd/ci/variants.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ func variantScope(repos []string) string {
4545
return strings.Join(repos, ",")
4646
}
4747

48-
func secretVariantRepositoryMatches(variant api.CISecretVariant, repos []string) bool {
49-
return variantAttributesMatch(variant.Attributes, repos, nil, nil, nil)
50-
}
51-
52-
func variableVariantRepositoryMatches(variant api.CIVariableVariant, repos []string) bool {
53-
return variantAttributesMatch(variant.Attributes, repos, nil, nil, nil)
54-
}
55-
5648
func filterSecretVariants(secret api.CISecretGroup, repo, environment, branch, workflow []string) api.CISecretGroup {
5749
if len(repo) == 0 && len(environment) == 0 && len(branch) == 0 && len(workflow) == 0 {
5850
return secret

pkg/cmd/ci/vars.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package ci
22

33
import (
4-
"encoding/json"
54
"fmt"
6-
"os"
75
"strings"
86

97
"github.com/depot/cli/pkg/api"
@@ -324,6 +322,9 @@ attributes. Passing a variable name lists one grouped variable.`,
324322
Aliases: []string{"ls"},
325323
Args: cobra.MaximumNArgs(1),
326324
RunE: func(cmd *cobra.Command, args []string) error {
325+
if err := validateTextOrJSONOutput(output); err != nil {
326+
return err
327+
}
327328
ctx := cmd.Context()
328329

329330
if orgID == "" {
@@ -360,10 +361,8 @@ attributes. Passing a variable name lists one grouped variable.`,
360361
}
361362
}
362363

363-
if output == "json" {
364-
enc := json.NewEncoder(os.Stdout)
365-
enc.SetIndent("", " ")
366-
return enc.Encode(result)
364+
if outputIsJSON(output) {
365+
return writeJSON(result)
367366
}
368367

369368
if len(result.Variables) == 0 {

0 commit comments

Comments
 (0)