Skip to content

Commit c6a4d3f

Browse files
feat(commands/service/alert): convert alerts to service alert
BREAKING CHANGE:
1 parent 90809dc commit c6a4d3f

19 files changed

Lines changed: 250 additions & 27 deletions

File tree

pkg/commands/alias/alert/create.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// CreateCommand wraps the CreateCommand from the newcmd package.
14+
type CreateCommand struct {
15+
*newcmd.CreateCommand
16+
}
17+
18+
// NewCreateCommand returns a usable command registered under the parent.
19+
func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand {
20+
c := CreateCommand{newcmd.NewCreateCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert create' command instead.")
28+
return c.CreateCommand.Exec(in, out)
29+
}

pkg/commands/alias/alert/delete.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// DeleteCommand wraps the DeleteCommand from the newcmd package.
14+
type DeleteCommand struct {
15+
*newcmd.DeleteCommand
16+
}
17+
18+
// NewDeleteCommand returns a usable command registered under the parent.
19+
func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteCommand {
20+
c := DeleteCommand{newcmd.NewDeleteCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert delete' command instead.")
28+
return c.DeleteCommand.Exec(in, out)
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// DescribeCommand wraps the DescribeCommand from the newcmd package.
14+
type DescribeCommand struct {
15+
*newcmd.DescribeCommand
16+
}
17+
18+
// NewDescribeCommand returns a usable command registered under the parent.
19+
func NewDescribeCommand(parent argparser.Registerer, g *global.Data) *DescribeCommand {
20+
c := DescribeCommand{newcmd.NewDescribeCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert describe' command instead.")
28+
return c.DescribeCommand.Exec(in, out)
29+
}

pkg/commands/alias/alert/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package alert contains deprecated aliases for the 'service alert' commands.
2+
package alert
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// ListHistoryCommand wraps the ListHistoryCommand from the newcmd package.
14+
type ListHistoryCommand struct {
15+
*newcmd.ListHistoryCommand
16+
}
17+
18+
// NewListCommand returns a usable command registered under the parent.
19+
func NewListHistoryCommand(parent argparser.Registerer, g *global.Data) *ListHistoryCommand {
20+
c := ListHistoryCommand{newcmd.NewListHistoryCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *ListHistoryCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert list history' command instead.")
28+
return c.ListHistoryCommand.Exec(in, out)
29+
}

pkg/commands/alias/alert/list.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// ListCommand wraps the ListCommand from the newcmd package.
14+
type ListCommand struct {
15+
*newcmd.ListCommand
16+
}
17+
18+
// NewListCommand returns a usable command registered under the parent.
19+
func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
20+
c := ListCommand{newcmd.NewListCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert list' command instead.")
28+
return c.ListCommand.Exec(in, out)
29+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package alerts
1+
package alert
22

33
import (
44
"io"
@@ -15,13 +15,13 @@ type RootCommand struct {
1515
}
1616

1717
// CommandName is the string to be used to invoke this command.
18-
const CommandName = "alerts"
18+
const CommandName = "alert"
1919

2020
// NewRootCommand returns a new command registered in the parent.
2121
func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand {
2222
var c RootCommand
2323
c.Globals = g
24-
c.CmdClause = parent.Command(CommandName, "Manipulate Fastly Alerts")
24+
c.CmdClause = parent.Command(CommandName, "Manipulate Fastly Alerts").Hidden()
2525
return &c
2626
}
2727

pkg/commands/alias/alert/update.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package alert
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/alert"
7+
8+
"github.com/fastly/cli/pkg/argparser"
9+
"github.com/fastly/cli/pkg/global"
10+
"github.com/fastly/cli/pkg/text"
11+
)
12+
13+
// UpdateCommand wraps the UpdateCommand from the newcmd package.
14+
type UpdateCommand struct {
15+
*newcmd.UpdateCommand
16+
}
17+
18+
// NewUpdateCommand returns a usable command registered under the parent.
19+
func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateCommand {
20+
c := UpdateCommand{newcmd.NewUpdateCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service alert update' command instead.")
28+
return c.UpdateCommand.Exec(in, out)
29+
}

pkg/commands/commands.go

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"github.com/fastly/kingpin"
55

66
"github.com/fastly/cli/pkg/argparser"
7-
"github.com/fastly/cli/pkg/commands/alerts"
87
aliasacl "github.com/fastly/cli/pkg/commands/alias/acl"
98
aliasaclentry "github.com/fastly/cli/pkg/commands/alias/aclentry"
9+
aliasalert "github.com/fastly/cli/pkg/commands/alias/alert"
1010
aliasbackend "github.com/fastly/cli/pkg/commands/alias/backend"
1111
aliashealthcheck "github.com/fastly/cli/pkg/commands/alias/healthcheck"
1212
aliaspurge "github.com/fastly/cli/pkg/commands/alias/purge"
@@ -100,6 +100,7 @@ import (
100100
"github.com/fastly/cli/pkg/commands/service"
101101
serviceacl "github.com/fastly/cli/pkg/commands/service/acl"
102102
serviceaclentry "github.com/fastly/cli/pkg/commands/service/aclentry"
103+
servicealert "github.com/fastly/cli/pkg/commands/service/alert"
103104
servicebackend "github.com/fastly/cli/pkg/commands/service/backend"
104105
servicedomain "github.com/fastly/cli/pkg/commands/service/domain"
105106
servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck"
@@ -145,13 +146,6 @@ func Define( // nolint:revive // function-length
145146
// beginning of the list of commands.
146147
ssoCmdRoot := sso.NewRootCommand(app, data)
147148

148-
alertsCmdRoot := alerts.NewRootCommand(app, data)
149-
alertsCreate := alerts.NewCreateCommand(alertsCmdRoot.CmdClause, data)
150-
alertsDelete := alerts.NewDeleteCommand(alertsCmdRoot.CmdClause, data)
151-
alertsDescribe := alerts.NewDescribeCommand(alertsCmdRoot.CmdClause, data)
152-
alertsList := alerts.NewListCommand(alertsCmdRoot.CmdClause, data)
153-
alertsListHistory := alerts.NewListHistoryCommand(alertsCmdRoot.CmdClause, data)
154-
alertsUpdate := alerts.NewUpdateCommand(alertsCmdRoot.CmdClause, data)
155149
authtokenCmdRoot := authtoken.NewRootCommand(app, data)
156150
authtokenCreate := authtoken.NewCreateCommand(authtokenCmdRoot.CmdClause, data)
157151
authtokenDelete := authtoken.NewDeleteCommand(authtokenCmdRoot.CmdClause, data)
@@ -602,6 +596,13 @@ func Define( // nolint:revive // function-length
602596
serviceSearch := service.NewSearchCommand(serviceCmdRoot.CmdClause, data)
603597
serviceUpdate := service.NewUpdateCommand(serviceCmdRoot.CmdClause, data)
604598
servicePurge := servicepurge.NewPurgeCommand(serviceCmdRoot.CmdClause, data)
599+
servicealertCmdRoot := servicealert.NewRootCommand(serviceCmdRoot.CmdClause, data)
600+
servicealertCreate := servicealert.NewCreateCommand(servicealertCmdRoot.CmdClause, data)
601+
servicealertDelete := servicealert.NewDeleteCommand(servicealertCmdRoot.CmdClause, data)
602+
servicealertDescribe := servicealert.NewDescribeCommand(servicealertCmdRoot.CmdClause, data)
603+
servicealertList := servicealert.NewListCommand(servicealertCmdRoot.CmdClause, data)
604+
servicealertListHistory := servicealert.NewListHistoryCommand(servicealertCmdRoot.CmdClause, data)
605+
servicealertUpdate := servicealert.NewUpdateCommand(servicealertCmdRoot.CmdClause, data)
605606
serviceaclCmdRoot := serviceacl.NewRootCommand(serviceCmdRoot.CmdClause, data)
606607
serviceaclCreate := serviceacl.NewCreateCommand(serviceaclCmdRoot.CmdClause, data)
607608
serviceaclDelete := serviceacl.NewDeleteCommand(serviceaclCmdRoot.CmdClause, data)
@@ -736,6 +737,13 @@ func Define( // nolint:revive // function-length
736737
aliasHealthcheckList := aliashealthcheck.NewListCommand(aliasHealthcheckRoot.CmdClause, data)
737738
aliasHealthcheckUpdate := aliashealthcheck.NewUpdateCommand(aliasHealthcheckRoot.CmdClause, data)
738739
aliasPurge := aliaspurge.NewCommand(app, data)
740+
aliasAlertRoot := aliasalert.NewRootCommand(app, data)
741+
aliasAlertCreate := aliasalert.NewCreateCommand(aliasAlertRoot.CmdClause, data)
742+
aliasAlertDelete := aliasalert.NewDeleteCommand(aliasAlertRoot.CmdClause, data)
743+
aliasAlertDescribe := aliasalert.NewDescribeCommand(aliasAlertRoot.CmdClause, data)
744+
aliasAlertList := aliasalert.NewListCommand(aliasAlertRoot.CmdClause, data)
745+
aliasAlertListHistory := aliasalert.NewListHistoryCommand(aliasAlertRoot.CmdClause, data)
746+
aliasAlertUpdate := aliasalert.NewUpdateCommand(aliasAlertRoot.CmdClause, data)
739747
aliasACLRoot := aliasacl.NewRootCommand(app, data)
740748
aliasACLCreate := aliasacl.NewCreateCommand(aliasACLRoot.CmdClause, data)
741749
aliasACLDelete := aliasacl.NewDeleteCommand(aliasACLRoot.CmdClause, data)
@@ -780,12 +788,6 @@ func Define( // nolint:revive // function-length
780788

781789
return []argparser.Command{
782790
shellcompleteCmdRoot,
783-
alertsCreate,
784-
alertsDelete,
785-
alertsDescribe,
786-
alertsList,
787-
alertsListHistory,
788-
alertsUpdate,
789791
authtokenCmdRoot,
790792
authtokenCreate,
791793
authtokenDelete,
@@ -1230,6 +1232,12 @@ func Define( // nolint:revive // function-length
12301232
serviceSearch,
12311233
serviceUpdate,
12321234
servicePurge,
1235+
servicealertCreate,
1236+
servicealertDelete,
1237+
servicealertDescribe,
1238+
servicealertList,
1239+
servicealertListHistory,
1240+
servicealertUpdate,
12331241
serviceaclCmdRoot,
12341242
serviceaclCreate,
12351243
serviceaclDelete,
@@ -1361,6 +1369,13 @@ func Define( // nolint:revive // function-length
13611369
aliasHealthcheckList,
13621370
aliasHealthcheckUpdate,
13631371
aliasPurge,
1372+
aliasAlertRoot,
1373+
aliasAlertCreate,
1374+
aliasAlertDelete,
1375+
aliasAlertDescribe,
1376+
aliasAlertList,
1377+
aliasAlertListHistory,
1378+
aliasAlertUpdate,
13641379
aliasACLCreate,
13651380
aliasACLDelete,
13661381
aliasACLDescribe,
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"testing"
77
"time"
88

9-
root "github.com/fastly/cli/pkg/commands/alerts"
9+
root "github.com/fastly/cli/pkg/commands/service"
10+
sub "github.com/fastly/cli/pkg/commands/service/alert"
1011
"github.com/fastly/cli/pkg/mock"
1112
"github.com/fastly/cli/pkg/testutil"
1213
"github.com/fastly/go-fastly/v12/fastly"
@@ -98,7 +99,7 @@ func TestAlertsCreate(t *testing.T) {
9899
},
99100
}
100101

101-
testutil.RunCLIScenarios(t, []string{root.CommandName, "create"}, scenarios)
102+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "create"}, scenarios)
102103
}
103104

104105
func TestAlertsUpdate(t *testing.T) {
@@ -186,7 +187,7 @@ func TestAlertsUpdate(t *testing.T) {
186187
},
187188
}
188189

189-
testutil.RunCLIScenarios(t, []string{root.CommandName, "update"}, scenarios)
190+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "update"}, scenarios)
190191
}
191192

192193
func TestAlertsDelete(t *testing.T) {
@@ -206,7 +207,7 @@ func TestAlertsDelete(t *testing.T) {
206207
},
207208
}
208209

209-
testutil.RunCLIScenarios(t, []string{root.CommandName, "delete"}, scenarios)
210+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "delete"}, scenarios)
210211
}
211212

212213
func TestAlertsDescribe(t *testing.T) {
@@ -228,7 +229,7 @@ func TestAlertsDescribe(t *testing.T) {
228229
},
229230
}
230231

231-
testutil.RunCLIScenarios(t, []string{root.CommandName, "describe"}, scenarios)
232+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "describe"}, scenarios)
232233
}
233234

234235
func TestAlertsList(t *testing.T) {
@@ -308,7 +309,7 @@ func TestAlertsList(t *testing.T) {
308309
},
309310
}
310311

311-
testutil.RunCLIScenarios(t, []string{root.CommandName, "list"}, scenarios)
312+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "list"}, scenarios)
312313
}
313314

314315
func TestAlertsHistoryList(t *testing.T) {
@@ -388,7 +389,7 @@ func TestAlertsHistoryList(t *testing.T) {
388389
},
389390
}
390391

391-
testutil.RunCLIScenarios(t, []string{root.CommandName, "history"}, scenarios)
392+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "history"}, scenarios)
392393
}
393394

394395
type flag struct {

0 commit comments

Comments
 (0)