Skip to content

Commit 5ce8043

Browse files
authored
[CDTOOL-1258] Move imageoptimizerdefaults commands under service (#1627)
### Change summary This PR moves the `imageoptimizerdefaults` command under the `service` command. A alias for `fastly imageoptimizerdefaults` is added here to prevent breaking changes. All Submissions: * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [x] Does your submission pass tests? ``` make test TEST_ARGS="-run TestImageOptimizerDefaultsUpdate ./pkg/commands/service/imageoptimizerdefaults" ok github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults 1.117s make test TEST_ARGS="-run TestImageOptimizerDefaultsGet ./pkg/commands/service/imageoptimizerdefaults" ok github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults 1.086s ``` ### Changes to Core Features: * [ ] Have you written new tests for your core changes, as applicable? * [x] Have you successfully run tests with your changes locally? ### User Impact None, an alias has been made.
1 parent 541957d commit 5ce8043

12 files changed

Lines changed: 109 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- feat(service/backend): moved the `backend` command under the `service` command, with an unlisted and deprecated alias of `backend` ([#1621](https://github.com/fastly/cli/pull/1621))
1919
- feat(service/backend): moved the `acl` and `aclentry` commands under the `service` command, with a unlisted and deprecated aliases of `acl` and `aclentry` ([#1621](https://github.com/fastly/cli/pull/1624))
2020
- feat(version): If the latest version is at least one major version higher than the current version, provide links to the release notes for the major version(s) so the user can review them before upgrading. ([#1623](https://github.com/fastly/cli/pull/1623))
21+
- feat(service/imageoptimizerdefaults): moved the `imageoptimizerdefaults` commands under the `service` command, with an unlisted and deprecated alias of `imageoptimizerdefaults` ([#1627](https://github.com/fastly/cli/pull/1627))
2122
- feat(service/alert): moved the `alerts` command to the `service alert` command, with an unlisted and deprecated alias of `alerts` ([#1616](https://github.com/fastly/cli/pull/1626))
2223

2324
### Bug fixes:

pkg/app/run_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ dashboard
6969
dictionary
7070
dictionary-entry
7171
domain
72-
imageoptimizer
7372
install
7473
ip-list
7574
kv-store
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package imageoptimizerdefaults contains deprecated aliases for the 'service imageoptimizerdefaults' commands.
2+
package imageoptimizerdefaults
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package imageoptimizerdefaults
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults"
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+
// GetCommand wraps the GetCommand from the newcmd package.
14+
type GetCommand struct {
15+
*newcmd.GetCommand
16+
}
17+
18+
// NewGetCommand returns a usable command registered under the parent.
19+
func NewGetCommand(parent argparser.Registerer, g *global.Data) *GetCommand {
20+
c := GetCommand{newcmd.NewGetCommand(parent, g)}
21+
c.CmdClause.Hidden()
22+
return &c
23+
}
24+
25+
// Exec implements the command interface.
26+
func (c *GetCommand) Exec(in io.Reader, out io.Writer) error {
27+
text.Deprecated(out, "Use the 'service imageoptimizerdefaults get' command instead.")
28+
return c.GetCommand.Exec(in, out)
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package imageoptimizerdefaults
2+
3+
import (
4+
"io"
5+
6+
"github.com/fastly/cli/pkg/argparser"
7+
"github.com/fastly/cli/pkg/global"
8+
)
9+
10+
// RootCommand is the parent command for all subcommands in this package.
11+
// It should be installed under the primary root command.
12+
type RootCommand struct {
13+
argparser.Base
14+
// no flags
15+
}
16+
17+
// CommandName is the string to be used to invoke this command.
18+
const CommandName = "imageoptimizerdefaults"
19+
20+
// NewRootCommand returns a new command registered in the parent.
21+
func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand {
22+
var c RootCommand
23+
c.Globals = g
24+
c.CmdClause = parent.Command(CommandName, "Manipulate Fastly Image Optimizer Defaults").Hidden()
25+
return &c
26+
}
27+
28+
// Exec implements the command interface.
29+
func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error {
30+
panic("unreachable")
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package imageoptimizerdefaults
2+
3+
import (
4+
"io"
5+
6+
newcmd "github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults"
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 imageoptimizerdefaults update' command instead.")
28+
return c.UpdateCommand.Exec(in, out)
29+
}

pkg/commands/commands.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
aliasalerts "github.com/fastly/cli/pkg/commands/alias/alerts"
1010
aliasbackend "github.com/fastly/cli/pkg/commands/alias/backend"
1111
aliashealthcheck "github.com/fastly/cli/pkg/commands/alias/healthcheck"
12+
aliasimageoptimizerdefaults "github.com/fastly/cli/pkg/commands/alias/imageoptimizerdefaults"
1213
aliaspurge "github.com/fastly/cli/pkg/commands/alias/purge"
1314
aliasserviceversion "github.com/fastly/cli/pkg/commands/alias/serviceversion"
1415
aliasvcl "github.com/fastly/cli/pkg/commands/alias/vcl"
@@ -26,7 +27,6 @@ import (
2627
"github.com/fastly/cli/pkg/commands/dictionary"
2728
"github.com/fastly/cli/pkg/commands/dictionaryentry"
2829
"github.com/fastly/cli/pkg/commands/domain"
29-
"github.com/fastly/cli/pkg/commands/imageoptimizerdefaults"
3030
"github.com/fastly/cli/pkg/commands/install"
3131
"github.com/fastly/cli/pkg/commands/ip"
3232
"github.com/fastly/cli/pkg/commands/kvstore"
@@ -104,6 +104,7 @@ import (
104104
servicebackend "github.com/fastly/cli/pkg/commands/service/backend"
105105
servicedomain "github.com/fastly/cli/pkg/commands/service/domain"
106106
servicehealthcheck "github.com/fastly/cli/pkg/commands/service/healthcheck"
107+
serviceimageoptimizerdefaults "github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults"
107108
servicepurge "github.com/fastly/cli/pkg/commands/service/purge"
108109
servicevcl "github.com/fastly/cli/pkg/commands/service/vcl"
109110
servicevclcondition "github.com/fastly/cli/pkg/commands/service/vcl/condition"
@@ -213,9 +214,6 @@ func Define( // nolint:revive // function-length
213214
domainDescribe := domain.NewDescribeCommand(domainCmdRoot.CmdClause, data)
214215
domainList := domain.NewListCommand(domainCmdRoot.CmdClause, data)
215216
domainUpdate := domain.NewUpdateCommand(domainCmdRoot.CmdClause, data)
216-
imageoptimizerdefaultsCmdRoot := imageoptimizerdefaults.NewRootCommand(app, data)
217-
imageoptimizerdefaultsGet := imageoptimizerdefaults.NewGetCommand(imageoptimizerdefaultsCmdRoot.CmdClause, data)
218-
imageoptimizerdefaultsUpdate := imageoptimizerdefaults.NewUpdateCommand(imageoptimizerdefaultsCmdRoot.CmdClause, data)
219217
installRoot := install.NewRootCommand(app, data)
220218
ipCmdRoot := ip.NewRootCommand(app, data)
221219
kvstoreCmdRoot := kvstore.NewRootCommand(app, data)
@@ -669,6 +667,9 @@ func Define( // nolint:revive // function-length
669667
servicehealthcheckDescribe := servicehealthcheck.NewDescribeCommand(servicehealthcheckCmdRoot.CmdClause, data)
670668
servicehealthcheckList := servicehealthcheck.NewListCommand(servicehealthcheckCmdRoot.CmdClause, data)
671669
servicehealthcheckUpdate := servicehealthcheck.NewUpdateCommand(servicehealthcheckCmdRoot.CmdClause, data)
670+
serviceimageoptimizerdefaultsCmdRoot := serviceimageoptimizerdefaults.NewRootCommand(serviceCmdRoot.CmdClause, data)
671+
serviceimageoptimizerdefaultsGet := serviceimageoptimizerdefaults.NewGetCommand(serviceimageoptimizerdefaultsCmdRoot.CmdClause, data)
672+
serviceimageoptimizerdefaultsUpdate := serviceimageoptimizerdefaults.NewUpdateCommand(serviceimageoptimizerdefaultsCmdRoot.CmdClause, data)
672673
statsCmdRoot := stats.NewRootCommand(app, data)
673674
statsHistorical := stats.NewHistoricalCommand(statsCmdRoot.CmdClause, data)
674675
statsRealtime := stats.NewRealtimeCommand(statsCmdRoot.CmdClause, data)
@@ -736,6 +737,9 @@ func Define( // nolint:revive // function-length
736737
aliasHealthcheckDescribe := aliashealthcheck.NewDescribeCommand(aliasHealthcheckRoot.CmdClause, data)
737738
aliasHealthcheckList := aliashealthcheck.NewListCommand(aliasHealthcheckRoot.CmdClause, data)
738739
aliasHealthcheckUpdate := aliashealthcheck.NewUpdateCommand(aliasHealthcheckRoot.CmdClause, data)
740+
aliasimageoptimizerdefaultsRoot := aliasimageoptimizerdefaults.NewRootCommand(app, data)
741+
aliasimageoptimizerdefaultsGet := aliasimageoptimizerdefaults.NewGetCommand(aliasimageoptimizerdefaultsRoot.CmdClause, data)
742+
aliasimageoptimizerdefaultsUpdate := aliasimageoptimizerdefaults.NewUpdateCommand(aliasimageoptimizerdefaultsRoot.CmdClause, data)
739743
aliasPurge := aliaspurge.NewCommand(app, data)
740744
aliasAlertRoot := aliasalerts.NewRootCommand(app, data)
741745
aliasAlertCreate := aliasalerts.NewCreateCommand(aliasAlertRoot.CmdClause, data)
@@ -855,9 +859,6 @@ func Define( // nolint:revive // function-length
855859
domainDescribe,
856860
domainList,
857861
domainUpdate,
858-
imageoptimizerdefaultsCmdRoot,
859-
imageoptimizerdefaultsGet,
860-
imageoptimizerdefaultsUpdate,
861862
installRoot,
862863
ipCmdRoot,
863864
kvstoreCreate,
@@ -1295,6 +1296,9 @@ func Define( // nolint:revive // function-length
12951296
servicehealthcheckDescribe,
12961297
servicehealthcheckList,
12971298
servicehealthcheckUpdate,
1299+
serviceimageoptimizerdefaultsCmdRoot,
1300+
serviceimageoptimizerdefaultsGet,
1301+
serviceimageoptimizerdefaultsUpdate,
12981302
serviceVersionActivate,
12991303
serviceVersionClone,
13001304
serviceVersionCmdRoot,
@@ -1368,6 +1372,8 @@ func Define( // nolint:revive // function-length
13681372
aliasHealthcheckDescribe,
13691373
aliasHealthcheckList,
13701374
aliasHealthcheckUpdate,
1375+
aliasimageoptimizerdefaultsGet,
1376+
aliasimageoptimizerdefaultsUpdate,
13711377
aliasPurge,
13721378
aliasAlertRoot,
13731379
aliasAlertCreate,
File renamed without changes.
File renamed without changes.

pkg/commands/imageoptimizerdefaults/imageoptimizer_test.go renamed to pkg/commands/service/imageoptimizerdefaults/imageoptimizer_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77

88
"github.com/fastly/go-fastly/v12/fastly"
99

10-
root "github.com/fastly/cli/pkg/commands/imageoptimizerdefaults"
10+
root "github.com/fastly/cli/pkg/commands/service"
11+
sub "github.com/fastly/cli/pkg/commands/service/imageoptimizerdefaults"
1112
"github.com/fastly/cli/pkg/mock"
1213
"github.com/fastly/cli/pkg/testutil"
1314
)
@@ -107,7 +108,7 @@ func TestImageOptimizerDefaultsUpdate(t *testing.T) {
107108
WantError: errTest.Error(),
108109
},
109110
}
110-
testutil.RunCLIScenarios(t, []string{root.CommandName, "update"}, scenarios)
111+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "update"}, scenarios)
111112
}
112113

113114
func updateImageOptimizerDefaultsOK(_ context.Context, _ *fastly.UpdateImageOptimizerDefaultSettingsInput) (*fastly.ImageOptimizerDefaultSettings, error) {
@@ -220,7 +221,7 @@ func TestImageOptimizerDefaultsGet(t *testing.T) {
220221
WantError: errTest.Error(),
221222
},
222223
}
223-
testutil.RunCLIScenarios(t, []string{root.CommandName, "get"}, scenarios)
224+
testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "get"}, scenarios)
224225
}
225226

226227
func getImageOptimizerDefaultsOK(_ context.Context, _ *fastly.GetImageOptimizerDefaultSettingsInput) (*fastly.ImageOptimizerDefaultSettings, error) {

0 commit comments

Comments
 (0)