11package cmd
22
33import (
4+ "context"
5+
46 "github.com/spf13/cobra"
57
68 "github.com/render-oss/cli/pkg/client"
@@ -12,7 +14,7 @@ import (
1214 kvtypes "github.com/render-oss/cli/pkg/types/keyvalue"
1315)
1416
15- func newKVListCmd (_ * dependencies.Dependencies ) * cobra.Command {
17+ func newKVListCmd (deps * dependencies.Dependencies ) * cobra.Command {
1618 cmd := & cobra.Command {
1719 Use : "list" ,
1820 Short : "List Key Value store instances" ,
@@ -53,23 +55,31 @@ resolved within that project.`,
5355 }
5456 input = kvtypes .NormalizeListInput (input )
5557
56- _ , err := command .NonInteractive (cmd , func () ([] * keyvalue.Model , error ) {
58+ _ , err := command .NonInteractive (cmd , func () (* keyvalue.KeyValueListOut , error ) {
5759 params := & client.ListKeyValueParams {}
5860
59- envIDs , ok , err := resolveListEnvIDs (cmd , input )
61+ envIDs , ok , err := resolveListEnvIDs (cmd . Context (), deps , input )
6062 if err != nil {
6163 return nil , err
6264 }
6365 if ok {
6466 if len (envIDs ) == 0 {
65- return nil , nil
67+ out := keyvalue .NewKeyValueListOut (nil )
68+ return & out , nil
6669 }
6770 envParam := client .EnvironmentIdParam (envIDs )
6871 params .EnvironmentId = & envParam
6972 }
7073
71- return keyvalue .List (cmd .Context (), params )
72- }, text .KeyValueTable )
74+ models , err := deps .KeyValueService ().ListKeyValue (cmd .Context (), params )
75+ if err != nil {
76+ return nil , err
77+ }
78+ out := keyvalue .NewKeyValueListOut (models )
79+ return & out , nil
80+ }, func (out * keyvalue.KeyValueListOut ) string {
81+ return text .KeyValueTable (out .Data )
82+ })
7383 return err
7484 }
7585
@@ -79,16 +89,12 @@ resolved within that project.`,
7989// resolveListEnvIDs translates --project/--environment selectors into the
8090// environment IDs to filter on. The second return value is true when the
8191// caller should apply an environment filter; false means list workspace-wide.
82- func resolveListEnvIDs (cmd * cobra. Command , input kvtypes.KeyValueListInput ) ([]string , bool , error ) {
92+ func resolveListEnvIDs (ctx context. Context , deps * dependencies. Dependencies , input kvtypes.KeyValueListInput ) ([]string , bool , error ) {
8393 if input .ProjectIDOrName == nil && input .EnvironmentIDOrName == nil {
8494 return nil , false , nil
8595 }
8696
87- c , err := client .NewDefaultClient ()
88- if err != nil {
89- return nil , false , err
90- }
91- scope , err := resolve .NewFromClient (c ).ResolveScopeInActiveWorkspace (cmd .Context (), resolve.ActiveWorkspaceScopeInput {
97+ scope , err := deps .Resolver ().ResolveScopeInActiveWorkspace (ctx , resolve.ActiveWorkspaceScopeInput {
9298 ProjectIDOrName : input .ProjectIDOrName ,
9399 EnvironmentIDOrName : input .EnvironmentIDOrName ,
94100 })
0 commit comments