From 41ab2106e788be8a8f239a334ac7dd231c90f3a2 Mon Sep 17 00:00:00 2001 From: Integralist Date: Tue, 31 Oct 2023 14:19:36 +0000 Subject: [PATCH] feat: add --consistency flag to kv-store-entry list command --- go.mod | 2 +- go.sum | 4 ++-- pkg/app/usage.go | 1 + pkg/commands/kvstoreentry/list.go | 19 +++++++++++++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ad2d20c42..f878038f0 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( ) require ( - github.com/fastly/go-fastly/v8 v8.6.3 + github.com/fastly/go-fastly/v8 v8.6.4 github.com/kennygrant/sanitize v1.2.4 github.com/mholt/archiver v3.1.1+incompatible github.com/otiai10/copy v1.14.0 diff --git a/go.sum b/go.sum index 411b4e40f..aaa138ea6 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6 github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY= github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8= -github.com/fastly/go-fastly/v8 v8.6.3 h1:tzi0fbV63TjCcvx0kzr30NX4ZyuURj5LE7BB5+NDOXU= -github.com/fastly/go-fastly/v8 v8.6.3/go.mod h1:sC3WMOjQxwXk+gRI68ooTJJsI+/6AMA/4JLvrhNgpVk= +github.com/fastly/go-fastly/v8 v8.6.4 h1:/jf1j8VwpXDR+b7PA6RBhBcRo3OoEWFwFHFeOba7pk8= +github.com/fastly/go-fastly/v8 v8.6.4/go.mod h1:sC3WMOjQxwXk+gRI68ooTJJsI+/6AMA/4JLvrhNgpVk= github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk= github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= diff --git a/pkg/app/usage.go b/pkg/app/usage.go index 1aae6362a..0f85d8d24 100644 --- a/pkg/app/usage.go +++ b/pkg/app/usage.go @@ -148,6 +148,7 @@ var UsageTemplateFuncs = template.FuncMap{ var globalFlags = map[string]bool{ "accept-defaults": true, "auto-yes": true, + "debug-mode": true, "help": true, "non-interactive": true, "profile": true, diff --git a/pkg/commands/kvstoreentry/list.go b/pkg/commands/kvstoreentry/list.go index 5ff467768..2cf3fd386 100644 --- a/pkg/commands/kvstoreentry/list.go +++ b/pkg/commands/kvstoreentry/list.go @@ -18,8 +18,15 @@ type ListCommand struct { cmd.Base cmd.JSONOutput - manifest manifest.Data - Input fastly.ListKVStoreKeysInput + consistency string + manifest manifest.Data + Input fastly.ListKVStoreKeysInput +} + +// ConsistencyOptions is a list of allowed consistency values. +var ConsistencyOptions = []string{ + "eventual", + "strong", } // NewListCommand returns a usable command registered under the parent. @@ -37,6 +44,7 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis c.CmdClause.Flag("store-id", "Store ID").Short('s').Required().StringVar(&c.Input.ID) // Optional. + c.CmdClause.Flag("consistency", "Determines accuracy of results. i.e. 'eventual' uses caching to improve performance").Default("strong").HintOptions(ConsistencyOptions...).EnumVar(&c.consistency, ConsistencyOptions...) c.RegisterFlagBool(c.JSONFlag()) // --json return &c } @@ -70,6 +78,13 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error { spinner.Message(msg + "... (this can take a few minutes depending on the number of entries)") } + switch c.consistency { + case "eventual": + c.Input.Consistency = fastly.ConsistencyEventual + case "strong": + c.Input.Consistency = fastly.ConsistencyStrong + } + for { o, err := c.Globals.APIClient.ListKVStoreKeys(&c.Input) if err != nil {