Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): support --json for service search subcommand #911

Merged
merged 2 commits into from
Apr 17, 2023
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
10 changes: 5 additions & 5 deletions pkg/commands/configstore/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ type CreateCommand struct {
}

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

o, err := cmd.Globals.APIClient.CreateConfigStore(&cmd.input)
o, err := c.Globals.APIClient.CreateConfigStore(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/commands/configstore/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ type DeleteCommand struct {
}

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

err := cmd.Globals.APIClient.DeleteConfigStore(&cmd.input)
err := c.Globals.APIClient.DeleteConfigStore(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if cmd.JSONOutput.Enabled {
if c.JSONOutput.Enabled {
o := struct {
ID string `json:"id"`
Deleted bool `json:"deleted"`
}{
cmd.input.ID,
c.input.ID,
true,
}
_, err := cmd.WriteJSON(out, o)
_, err := c.WriteJSON(out, o)
return err
}

text.Success(out, "Deleted config store %s", cmd.input.ID)
text.Success(out, "Deleted config store %s", c.input.ID)

return nil
}
20 changes: 10 additions & 10 deletions pkg/commands/configstore/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ type DescribeCommand struct {
}

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

cs, err := cmd.Globals.APIClient.GetConfigStore(&cmd.input)
cs, err := c.Globals.APIClient.GetConfigStore(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

var csm *fastly.ConfigStoreMetadata
if cmd.metadata {
csm, err = cmd.Globals.APIClient.GetConfigStoreMetadata(&fastly.GetConfigStoreMetadataInput{
ID: cmd.input.ID,
if c.metadata {
csm, err = c.Globals.APIClient.GetConfigStoreMetadata(&fastly.GetConfigStoreMetadataInput{
ID: c.input.ID,
})
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}
}

if cmd.JSONOutput.Enabled {
if c.JSONOutput.Enabled {
// Create an ad-hoc structure for JSON representation of the config store
// and its metadata.
data := struct {
Expand All @@ -81,7 +81,7 @@ func (cmd *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
Metadata: csm,
}

if ok, err := cmd.WriteJSON(out, data); ok {
if ok, err := c.WriteJSON(out, data); ok {
return err
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/configstore/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ type ListCommand struct {
}

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

o, err := cmd.Globals.APIClient.ListConfigStores()
o, err := c.Globals.APIClient.ListConfigStores()
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/configstore/list_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ type ListServicesCommand struct {
}

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

o, err := cmd.Globals.APIClient.ListConfigStoreServices(&cmd.input)
o, err := c.Globals.APIClient.ListConfigStoreServices(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/configstore/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ type UpdateCommand struct {
}

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

o, err := cmd.Globals.APIClient.UpdateConfigStore(&cmd.input)
o, err := c.Globals.APIClient.UpdateConfigStore(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/commands/configstoreentry/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ type CreateCommand struct {
}

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

if cmd.stdin {
if c.stdin {
// Determine if 'in' has data available.
if in == nil || text.IsTTY(in) {
return errNoSTDINData
Expand All @@ -81,25 +81,25 @@ func (cmd *CreateCommand) Exec(in io.Reader, out io.Writer) error {
return err
}

cmd.input.Value = string(value)
} else if cmd.input.Value == "" {
c.input.Value = string(value)
} else if c.input.Value == "" {
return errNoValue
}

if len(cmd.input.Key) > maxKeyLen {
if len(c.input.Key) > maxKeyLen {
return errMaxKeyLen
}
if len(cmd.input.Value) > maxValueLen {
if len(c.input.Value) > maxValueLen {
return errMaxValueLen
}

o, err := cmd.Globals.APIClient.CreateConfigStoreItem(&cmd.input)
o, err := c.Globals.APIClient.CreateConfigStoreItem(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/commands/configstoreentry/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ type DeleteCommand struct {
}

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

err := cmd.Globals.APIClient.DeleteConfigStoreItem(&cmd.input)
err := c.Globals.APIClient.DeleteConfigStoreItem(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if cmd.JSONOutput.Enabled {
if c.JSONOutput.Enabled {
o := struct {
StoreID string `json:"store_id"`
Key string `json:"item_key"`
Deleted bool `json:"deleted"`
}{
cmd.input.StoreID,
cmd.input.Key,
c.input.StoreID,
c.input.Key,
true,
}
_, err := cmd.WriteJSON(out, o)
_, err := c.WriteJSON(out, o)
return err
}

text.Success(out, "Deleted config store item %s from store %s", cmd.input.Key, cmd.input.StoreID)
text.Success(out, "Deleted config store item %s from store %s", c.input.Key, c.input.StoreID)

return nil
}
10 changes: 5 additions & 5 deletions pkg/commands/configstoreentry/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ type DescribeCommand struct {
}

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

o, err := cmd.Globals.APIClient.GetConfigStoreItem(&cmd.input)
o, err := c.Globals.APIClient.GetConfigStoreItem(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/configstoreentry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ type ListCommand struct {
}

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

o, err := cmd.Globals.APIClient.ListConfigStoreItems(&cmd.input)
o, err := c.Globals.APIClient.ListConfigStoreItems(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/commands/configstoreentry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ type UpdateCommand struct {
}

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

if cmd.stdin {
if c.stdin {
// Determine if 'in' has data available.
if in == nil || text.IsTTY(in) {
return errNoSTDINData
Expand All @@ -87,30 +87,30 @@ func (cmd *UpdateCommand) Exec(in io.Reader, out io.Writer) error {
return err
}

cmd.input.Value = string(value)
} else if cmd.input.Value == "" {
c.input.Value = string(value)
} else if c.input.Value == "" {
return errNoValue
}

if len(cmd.input.Key) > maxKeyLen {
if len(c.input.Key) > maxKeyLen {
return errMaxKeyLen
}
if len(cmd.input.Value) > maxValueLen {
if len(c.input.Value) > maxValueLen {
return errMaxValueLen
}

o, err := cmd.Globals.APIClient.UpdateConfigStoreItem(&cmd.input)
o, err := c.Globals.APIClient.UpdateConfigStoreItem(&c.input)
if err != nil {
cmd.Globals.ErrLog.Add(err)
c.Globals.ErrLog.Add(err)
return err
}

if ok, err := cmd.WriteJSON(out, o); ok {
if ok, err := c.WriteJSON(out, o); ok {
return err
}

var action string
if cmd.input.Upsert {
if c.input.Upsert {
// The Fastly API does not provide a way to determine if
// an item was created or updated when using 'upsert' operation.
action = "Created or updated"
Expand Down
Loading