Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions pkg/commands/kvstore/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type ListCommand struct {
cmd.JSONOutput

manifest manifest.Data
Input fastly.ListKVStoresInput
}

// NewListCommand returns a usable command registered under the parent.
Expand All @@ -38,28 +37,54 @@ func NewListCommand(parent cmd.Registerer, g *global.Data, m manifest.Data) *Lis
}

// Exec invokes the application logic for the command.
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
if c.Globals.Verbose() && c.JSONOutput.Enabled {
return fsterr.ErrInvalidVerboseJSONCombo
}

o, err := c.Globals.APIClient.ListKVStores(&c.Input)
if err != nil {
c.Globals.ErrLog.Add(err)
return err
}
var cursor string

if ok, err := c.WriteJSON(out, o); ok {
return err
}
for {
o, err := c.Globals.APIClient.ListKVStores(&fastly.ListKVStoresInput{
Cursor: cursor,
})
if err != nil {
c.Globals.ErrLog.Add(err)
return err
}

if o != nil {
for _, o := range o.Data {
// avoid gosec loop aliasing check :/
o := o
text.PrintKVStore(out, "", &o)
if ok, err := c.WriteJSON(out, o); ok {
// No pagination prompt w/ JSON output.
// FIXME: This should be fixed here and for Secrets Store.
return err
}
}

return nil
if o != nil {
for _, o := range o.Data {
// avoid gosec loop aliasing check :/
o := o
text.PrintKVStore(out, "", &o)
}
if cur, ok := o.Meta["next_cursor"]; ok && cur != "" && cur != cursor {
// Check if 'out' is interactive before prompting.
if !c.Globals.Flags.NonInteractive && !c.Globals.Flags.AutoYes && text.IsTTY(out) {
text.Break(out)
printNext, err := text.AskYesNo(out, "Print next page [yes/no]: ", in)
if err != nil {
return err
}
if printNext {
cursor = cur
continue
}
} else {
// Otherwise if non-interactive or auto-yes, then load all data.
cursor = cur
continue
}
}
}

return nil
}
}
5 changes: 4 additions & 1 deletion pkg/commands/secretstore/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package secretstore
import (
"io"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/cmd"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// NewListCommand returns a usable command registered under the parent.
Expand All @@ -35,6 +36,7 @@ type ListCommand struct {
cmd.Base
cmd.JSONOutput

// NOTE: API returns 10 items even when --limit is set to smaller.
Input fastly.ListSecretStoresInput
manifest manifest.Data
}
Expand All @@ -54,6 +56,7 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {

if ok, err := c.WriteJSON(out, o); ok {
// No pagination prompt w/ JSON output.
// FIXME: This should be fixed here and for KV Store.
return err
}

Expand Down