github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/commands/secretstore/describe.go (about) 1 package secretstore 2 3 import ( 4 "io" 5 6 "github.com/fastly/go-fastly/v9/fastly" 7 8 "github.com/fastly/cli/pkg/argparser" 9 fsterr "github.com/fastly/cli/pkg/errors" 10 "github.com/fastly/cli/pkg/global" 11 "github.com/fastly/cli/pkg/text" 12 ) 13 14 // NewDescribeCommand returns a usable command registered under the parent. 15 func NewDescribeCommand(parent argparser.Registerer, g *global.Data) *DescribeCommand { 16 c := DescribeCommand{ 17 Base: argparser.Base{ 18 Globals: g, 19 }, 20 } 21 22 c.CmdClause = parent.Command("describe", "Retrieve a single secret store").Alias("get") 23 24 // Required. 25 c.RegisterFlag(argparser.StoreIDFlag(&c.Input.StoreID)) // --store-id 26 27 // Optional. 28 c.RegisterFlagBool(c.JSONFlag()) // --json 29 30 return &c 31 } 32 33 // DescribeCommand calls the Fastly API to describe an appropriate resource. 34 type DescribeCommand struct { 35 argparser.Base 36 argparser.JSONOutput 37 38 Input fastly.GetSecretStoreInput 39 } 40 41 // Exec invokes the application logic for the command. 42 func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error { 43 if c.Globals.Verbose() && c.JSONOutput.Enabled { 44 return fsterr.ErrInvalidVerboseJSONCombo 45 } 46 47 o, err := c.Globals.APIClient.GetSecretStore(&c.Input) 48 if err != nil { 49 c.Globals.ErrLog.Add(err) 50 return err 51 } 52 53 if ok, err := c.WriteJSON(out, o); ok { 54 return err 55 } 56 57 text.PrintSecretStore(out, "", o) 58 59 return nil 60 }