@@ -2,30 +2,33 @@ package productcore
22
33import (
44 "io"
5- "github.com/fastly/cli/pkg/api"
5+ fsterr "github.com/fastly/cli/pkg/errors"
6+
67 "github.com/fastly/cli/pkg/argparser"
78 "github.com/fastly/cli/pkg/global"
89 "github.com/fastly/cli/pkg/text"
910)
1011
11- // DisableFn is the type of the function that will be used to perform
12- // the disablement.
13- type DisableFn func (api.Interface , string ) error
14-
1512// Disable is a base type for all 'disable' commands.
16- type Disable struct {
13+ type Disable [ O any ] struct {
1714 Base
15+ hooks * EnablementHookFuncs [O ]
1816}
1917
2018// Init prepares the structure for use by the CLI core.
21- func (cmd * Disable ) Init (parent argparser.Registerer , g * global.Data , productName string ) {
19+ func (cmd * Disable [ O ] ) Init (parent argparser.Registerer , g * global.Data , productName string , hooks * EnablementHookFuncs [ O ] ) {
2220 cmd .CmdClause = parent .Command ("disable" , "Disable the " + productName + " product" )
21+ cmd .hooks = hooks
2322
2423 cmd .Base .Init (parent , g , productName )
2524}
2625
2726// Exec executes the disablement operation.
28- func (cmd * Disable ) Exec (out io.Writer , op DisableFn ) error {
27+ func (cmd * Disable [O ]) Exec (out io.Writer ) error {
28+ if cmd .Globals .Verbose () && cmd .JSONOutput .Enabled {
29+ return fsterr .ErrInvalidVerboseJSONCombo
30+ }
31+
2932 serviceID , source , flag , err := argparser .ServiceID (cmd .ServiceName , * cmd .Globals .Manifest , cmd .Globals .APIClient , cmd .Globals .ErrLog )
3033 if err != nil {
3134 cmd .Globals .ErrLog .Add (err )
@@ -36,14 +39,18 @@ func (cmd *Disable) Exec(out io.Writer, op DisableFn) error {
3639 argparser .DisplayServiceID (serviceID , flag , source , out )
3740 }
3841
39- err = op (cmd .Globals .APIClient , serviceID )
42+ err = cmd . hooks . DisableFunc (cmd .Globals .APIClient , serviceID )
4043 if err != nil {
4144 cmd .Globals .ErrLog .Add (err )
4245 return err
4346 }
4447
48+ if ok , err := cmd .WriteJSON (out , EnablementStatus {Enabled : false }); ok {
49+ return err
50+ }
51+
4552 text .Success (out ,
46- "Disabled " + cmd . ProductName + " on service %s" , serviceID )
53+ "Disabled %s on service %s" , cmd . ProductName , serviceID )
4754
4855 return nil
4956}
0 commit comments