11package productcore
22
33import (
4+ "fmt"
5+
46 "github.com/fastly/cli/pkg/api"
57 "github.com/fastly/cli/pkg/argparser"
68 "github.com/fastly/cli/pkg/global"
79 "github.com/fastly/cli/pkg/manifest"
10+ "github.com/fastly/go-fastly/v9/fastly/products"
811)
912
1013// Base is a base type for all product commands.
@@ -14,15 +17,11 @@ type Base struct {
1417 Manifest manifest.Data
1518
1619 ServiceName argparser.OptionalServiceNameID
17- ProductID string
18- ProductName string
1920}
2021
2122// Init prepares the structure for use by the CLI core.
22- func (cmd * Base ) Init (parent argparser.Registerer , g * global.Data , productID , productName string ) {
23+ func (cmd * Base ) Init (parent argparser.Registerer , g * global.Data ) {
2324 cmd .Globals = g
24- cmd .ProductID = productID
25- cmd .ProductName = productName
2625
2726 // Optional flags.
2827 cmd .RegisterFlag (argparser.StringFlagOpts {
@@ -40,16 +39,60 @@ func (cmd *Base) Init(parent argparser.Registerer, g *global.Data, productID, pr
4039 cmd .RegisterFlagBool (cmd .JSONFlag ()) // --json
4140}
4241
43- // EnablementStatus is a structure used to generate JSON output from
42+ // EnablementStatus is a structure used to generate output from
4443// the enablement-related commands
45- type EnablementStatus struct {
46- ProductID string `json:"product_id"`
47- Enabled bool `json:"enabled"`
44+ type EnablementStatus [_ products.ProductOutput ] struct {
45+ ProductName string `json:"-"`
46+ ProductID string `json:"product_id"`
47+ ServiceID string `json:"service_id"`
48+ Enabled bool `json:"enabled"`
49+ }
50+
51+ type StatusManager [O products.ProductOutput ] interface {
52+ SetEnabled (bool )
53+ GetEnabled () string
54+ GetProductName () string
55+ SetProductID (string )
56+ SetServiceID (string )
57+ TransformOutput (O )
58+ GetTextResult () string
59+ }
60+
61+ func (s * EnablementStatus [_ ]) SetEnabled (e bool ) {
62+ s .Enabled = e
63+ }
64+
65+ func (s * EnablementStatus [_ ]) GetEnabled () string {
66+ if s .Enabled {
67+ return "enabled"
68+ }
69+ return "disabled"
70+ }
71+
72+ func (s * EnablementStatus [_ ]) GetProductName () string {
73+ return s .ProductName
74+ }
75+
76+ func (s * EnablementStatus [_ ]) SetProductID (id string ) {
77+ s .ProductID = id
78+ }
79+
80+ func (s * EnablementStatus [_ ]) SetServiceID (id string ) {
81+ s .ServiceID = id
82+ }
83+
84+ func (s * EnablementStatus [O ]) TransformOutput (o O ) {
85+ s .ProductID = o .ProductID ()
86+ s .ServiceID = o .ServiceID ()
87+ }
88+
89+ func (s * EnablementStatus [O ]) GetTextResult () string {
90+ return fmt .Sprintf ("%s is %s on service %s" , s .ProductName , s .GetEnabled (), s .ServiceID )
4891}
4992
5093// EnablementHookFuncs is a structure of dependency-injection points
5194// used by unit tests to provide mock behaviors
52- type EnablementHookFuncs [O any ] struct {
95+ type EnablementHookFuncs [O products. ProductOutput ] struct {
5396 DisableFunc func (api.Interface , string ) error
5497 EnableFunc func (api.Interface , string ) (O , error )
5598 GetFunc func (api.Interface , string ) (O , error )
0 commit comments