@@ -2,30 +2,33 @@ package productcore
2
2
3
3
import (
4
4
"io"
5
- "github.com/fastly/cli/pkg/api"
5
+ fsterr "github.com/fastly/cli/pkg/errors"
6
+
6
7
"github.com/fastly/cli/pkg/argparser"
7
8
"github.com/fastly/cli/pkg/global"
8
9
"github.com/fastly/cli/pkg/text"
9
10
)
10
11
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
-
15
12
// Disable is a base type for all 'disable' commands.
16
- type Disable struct {
13
+ type Disable [ O any ] struct {
17
14
Base
15
+ hooks * EnablementHookFuncs [O ]
18
16
}
19
17
20
18
// 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 ] ) {
22
20
cmd .CmdClause = parent .Command ("disable" , "Disable the " + productName + " product" )
21
+ cmd .hooks = hooks
23
22
24
23
cmd .Base .Init (parent , g , productName )
25
24
}
26
25
27
26
// 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
+
29
32
serviceID , source , flag , err := argparser .ServiceID (cmd .ServiceName , * cmd .Globals .Manifest , cmd .Globals .APIClient , cmd .Globals .ErrLog )
30
33
if err != nil {
31
34
cmd .Globals .ErrLog .Add (err )
@@ -36,14 +39,18 @@ func (cmd *Disable) Exec(out io.Writer, op DisableFn) error {
36
39
argparser .DisplayServiceID (serviceID , flag , source , out )
37
40
}
38
41
39
- err = op (cmd .Globals .APIClient , serviceID )
42
+ err = cmd . hooks . DisableFunc (cmd .Globals .APIClient , serviceID )
40
43
if err != nil {
41
44
cmd .Globals .ErrLog .Add (err )
42
45
return err
43
46
}
44
47
48
+ if ok , err := cmd .WriteJSON (out , EnablementStatus {Enabled : false }); ok {
49
+ return err
50
+ }
51
+
45
52
text .Success (out ,
46
- "Disabled " + cmd . ProductName + " on service %s" , serviceID )
53
+ "Disabled %s on service %s" , cmd . ProductName , serviceID )
47
54
48
55
return nil
49
56
}
0 commit comments