Skip to content

Commit 064b085

Browse files
committed
Implemented Prefix for List Operations
1 parent 5092683 commit 064b085

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/commands/kvstoreentry/kvstoreentry_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ func TestListCommand(t *testing.T) {
264264
},
265265
WantOutput: strings.Join(testItems, "\n") + "\n",
266266
},
267+
{
268+
Name: "validate --prefix=foo",
269+
Args: fmt.Sprintf("--store-id %s --prefix=foo", storeID),
270+
API: mock.API{
271+
ListKVStoreKeysFn: func(_ context.Context, _ *fastly.ListKVStoreKeysInput) (*fastly.ListKVStoreKeysResponse, error) {
272+
return &fastly.ListKVStoreKeysResponse{Data: []string{"foo-key1", "foo-key2"}}, nil
273+
},
274+
},
275+
WantOutput: "✓ Getting data\nfoo-key1\nfoo-key2\n",
276+
},
267277
{
268278
Args: fmt.Sprintf("--store-id %s --json", storeID),
269279
API: mock.API{

pkg/commands/kvstoreentry/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ListCommand struct {
1919
argparser.JSONOutput
2020

2121
consistency string
22+
prefix string
2223
Input fastly.ListKVStoreKeysInput
2324
}
2425

@@ -43,6 +44,7 @@ func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
4344

4445
// Optional.
4546
c.CmdClause.Flag("consistency", "Determines accuracy of results. i.e. 'eventual' uses caching to improve performance").Default("strong").HintOptions(ConsistencyOptions...).EnumVar(&c.consistency, ConsistencyOptions...)
47+
c.CmdClause.Flag("prefix", "Restrict results to items whose keys match this prefix").StringVar(&c.prefix)
4648
c.RegisterFlagBool(c.JSONFlag()) // --json
4749
return &c
4850
}
@@ -83,6 +85,8 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
8385
c.Input.Consistency = fastly.ConsistencyStrong
8486
}
8587

88+
c.Input.Prefix = c.prefix
89+
8690
for {
8791
o, err := c.Globals.APIClient.ListKVStoreKeys(context.TODO(), &c.Input)
8892
if err != nil {

0 commit comments

Comments
 (0)