diff --git a/CHANGELOG.md b/CHANGELOG.md index f18dbec44..98dbe4a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - feat(compute/deploy): added the `--no-default-domain` flag to allow for the skipping of automatic domain creation when deploying a Compute service([#1610](https://github.com/fastly/cli/pull/1610)) - refactor(argparser/flags.go): add flag conversion utilities for converting string flags to bools and checking ascending and desecnding flags ([#1611](https://github.com/fastly/cli/pull/1611)) - feat(commands/service/purge): Add 'service purge' command as replacement for 'purge', with an unlisted and deprecated alias of 'purge'. ([#1612](https://github.com/fastly/cli/pull/1612)) +- feat(commands/service/version): Add 'service version ...' commands as replacements for 'service-version ...', with unlisted and deprecated aliases of 'service-version ...'. ([#1614](https://github.com/fastly/cli/pull/1614)) ### Bug fixes: diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index e951b37bc..89e610a90 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -93,7 +93,6 @@ secret-store secret-store-entry service service-auth -service-version stats tls-config tls-custom diff --git a/pkg/commands/alias/serviceversion/activate.go b/pkg/commands/alias/serviceversion/activate.go new file mode 100644 index 000000000..16646d353 --- /dev/null +++ b/pkg/commands/alias/serviceversion/activate.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// ActivateCommand wraps the ActivateCommand from the newcmd package. +type ActivateCommand struct { + *newcmd.ActivateCommand +} + +// NewActivateCommand returns a usable command registered under the parent. +func NewActivateCommand(parent argparser.Registerer, g *global.Data) *ActivateCommand { + c := ActivateCommand{newcmd.NewActivateCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *ActivateCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version activate' command instead.") + return c.ActivateCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/clone.go b/pkg/commands/alias/serviceversion/clone.go new file mode 100644 index 000000000..4ab3c8564 --- /dev/null +++ b/pkg/commands/alias/serviceversion/clone.go @@ -0,0 +1,31 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// CloneCommand wraps the CloneCommand from the newcmd package. +type CloneCommand struct { + *newcmd.CloneCommand +} + +// NewCloneCommand returns a usable command registered under the parent. +func NewCloneCommand(parent argparser.Registerer, g *global.Data) *CloneCommand { + c := CloneCommand{newcmd.NewCloneCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *CloneCommand) Exec(in io.Reader, out io.Writer) error { + if !c.JSONOutput.Enabled { + text.Deprecated(out, "Use the 'service version clone' command instead.") + } + return c.CloneCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/deactivate.go b/pkg/commands/alias/serviceversion/deactivate.go new file mode 100644 index 000000000..111798a10 --- /dev/null +++ b/pkg/commands/alias/serviceversion/deactivate.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// DeactivateCommand wraps the DeactivateCommand from the newcmd package. +type DeactivateCommand struct { + *newcmd.DeactivateCommand +} + +// NewDeactivateCommand returns a usable command registered under the parent. +func NewDeactivateCommand(parent argparser.Registerer, g *global.Data) *DeactivateCommand { + c := DeactivateCommand{newcmd.NewDeactivateCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *DeactivateCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version deactivate' command instead.") + return c.DeactivateCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/doc.go b/pkg/commands/alias/serviceversion/doc.go new file mode 100644 index 000000000..7b5c00fde --- /dev/null +++ b/pkg/commands/alias/serviceversion/doc.go @@ -0,0 +1,2 @@ +// Package serviceversion contains the 'service-version' aliases for the 'service version' commands. +package serviceversion diff --git a/pkg/commands/alias/serviceversion/list.go b/pkg/commands/alias/serviceversion/list.go new file mode 100644 index 000000000..ce15caf65 --- /dev/null +++ b/pkg/commands/alias/serviceversion/list.go @@ -0,0 +1,31 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// ListCommand wraps the ListCommand from the newcmd package. +type ListCommand struct { + *newcmd.ListCommand +} + +// NewListCommand returns a usable command registered under the parent. +func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand { + c := ListCommand{newcmd.NewListCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *ListCommand) Exec(in io.Reader, out io.Writer) error { + if !c.JSONOutput.Enabled { + text.Deprecated(out, "Use the 'service version list' command instead.") + } + return c.ListCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/lock.go b/pkg/commands/alias/serviceversion/lock.go new file mode 100644 index 000000000..7bb394794 --- /dev/null +++ b/pkg/commands/alias/serviceversion/lock.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// LockCommand wraps the LockCommand from the newcmd package. +type LockCommand struct { + *newcmd.LockCommand +} + +// NewLockCommand returns a usable command registered under the parent. +func NewLockCommand(parent argparser.Registerer, g *global.Data) *LockCommand { + c := LockCommand{newcmd.NewLockCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *LockCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version lock' command instead.") + return c.LockCommand.Exec(in, out) +} diff --git a/pkg/commands/serviceversion/root.go b/pkg/commands/alias/serviceversion/root.go similarity index 96% rename from pkg/commands/serviceversion/root.go rename to pkg/commands/alias/serviceversion/root.go index 551f1c4f6..4136824be 100644 --- a/pkg/commands/serviceversion/root.go +++ b/pkg/commands/alias/serviceversion/root.go @@ -21,7 +21,7 @@ const CommandName = "service-version" func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand { var c RootCommand c.Globals = g - c.CmdClause = parent.Command(CommandName, "Manipulate Fastly service versions") + c.CmdClause = parent.Command(CommandName, "Manipulate Fastly service versions").Hidden() return &c } diff --git a/pkg/commands/alias/serviceversion/stage.go b/pkg/commands/alias/serviceversion/stage.go new file mode 100644 index 000000000..1c687036b --- /dev/null +++ b/pkg/commands/alias/serviceversion/stage.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// StageCommand wraps the StageCommand from the newcmd package. +type StageCommand struct { + *newcmd.StageCommand +} + +// NewStageCommand returns a usable command registered under the parent. +func NewStageCommand(parent argparser.Registerer, g *global.Data) *StageCommand { + c := StageCommand{newcmd.NewStageCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *StageCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version stage' command instead.") + return c.StageCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/unstage.go b/pkg/commands/alias/serviceversion/unstage.go new file mode 100644 index 000000000..6afd513e2 --- /dev/null +++ b/pkg/commands/alias/serviceversion/unstage.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// UnstageCommand wraps the UnstageCommand from the newcmd package. +type UnstageCommand struct { + *newcmd.UnstageCommand +} + +// NewUnstageCommand returns a usable command registered under the parent. +func NewUnstageCommand(parent argparser.Registerer, g *global.Data) *UnstageCommand { + c := UnstageCommand{newcmd.NewUnstageCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *UnstageCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version unstage' command instead.") + return c.UnstageCommand.Exec(in, out) +} diff --git a/pkg/commands/alias/serviceversion/update.go b/pkg/commands/alias/serviceversion/update.go new file mode 100644 index 000000000..446510fe2 --- /dev/null +++ b/pkg/commands/alias/serviceversion/update.go @@ -0,0 +1,29 @@ +package serviceversion + +import ( + "io" + + newcmd "github.com/fastly/cli/pkg/commands/service/version" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" + "github.com/fastly/cli/pkg/text" +) + +// UpdateCommand wraps the UpdateCommand from the newcmd package. +type UpdateCommand struct { + *newcmd.UpdateCommand +} + +// NewUpdateCommand returns a usable command registered under the parent. +func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateCommand { + c := UpdateCommand{newcmd.NewUpdateCommand(parent, g)} + c.CmdClause.Hidden() + return &c +} + +// Exec implements the command interface. +func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) error { + text.Deprecated(out, "Use the 'service version update' command instead.") + return c.UpdateCommand.Exec(in, out) +} diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index 5dd59bd40..11cf4f921 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -8,6 +8,7 @@ import ( "github.com/fastly/cli/pkg/commands/aclentry" "github.com/fastly/cli/pkg/commands/alerts" aliaspurge "github.com/fastly/cli/pkg/commands/alias/purge" + aliasserviceversion "github.com/fastly/cli/pkg/commands/alias/serviceversion" "github.com/fastly/cli/pkg/commands/authtoken" "github.com/fastly/cli/pkg/commands/backend" "github.com/fastly/cli/pkg/commands/compute" @@ -95,8 +96,8 @@ import ( "github.com/fastly/cli/pkg/commands/secretstoreentry" "github.com/fastly/cli/pkg/commands/service" servicepurge "github.com/fastly/cli/pkg/commands/service/purge" + serviceversion "github.com/fastly/cli/pkg/commands/service/version" "github.com/fastly/cli/pkg/commands/serviceauth" - "github.com/fastly/cli/pkg/commands/serviceversion" "github.com/fastly/cli/pkg/commands/shellcomplete" "github.com/fastly/cli/pkg/commands/sso" "github.com/fastly/cli/pkg/commands/stats" @@ -630,7 +631,7 @@ func Define( // nolint:revive // function-length serviceauthDescribe := serviceauth.NewDescribeCommand(serviceauthCmdRoot.CmdClause, data) serviceauthList := serviceauth.NewListCommand(serviceauthCmdRoot.CmdClause, data) serviceauthUpdate := serviceauth.NewUpdateCommand(serviceauthCmdRoot.CmdClause, data) - serviceVersionCmdRoot := serviceversion.NewRootCommand(app, data) + serviceVersionCmdRoot := serviceversion.NewRootCommand(serviceCmdRoot.CmdClause, data) serviceVersionActivate := serviceversion.NewActivateCommand(serviceVersionCmdRoot.CmdClause, data) serviceVersionClone := serviceversion.NewCloneCommand(serviceVersionCmdRoot.CmdClause, data) serviceVersionDeactivate := serviceversion.NewDeactivateCommand(serviceVersionCmdRoot.CmdClause, data) @@ -715,6 +716,15 @@ func Define( // nolint:revive // function-length // Aliases for deprecated commands aliasPurge := aliaspurge.NewCommand(app, data) + aliasServiceVersionRoot := aliasserviceversion.NewRootCommand(app, data) + aliasServiceVersionActivate := aliasserviceversion.NewActivateCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionClone := aliasserviceversion.NewCloneCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionDeactivate := aliasserviceversion.NewDeactivateCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionList := aliasserviceversion.NewListCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionLock := aliasserviceversion.NewLockCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionStage := aliasserviceversion.NewStageCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionUnstage := aliasserviceversion.NewUnstageCommand(aliasServiceVersionRoot.CmdClause, data) + aliasServiceVersionUpdate := aliasserviceversion.NewUpdateCommand(aliasServiceVersionRoot.CmdClause, data) return []argparser.Command{ shellcompleteCmdRoot, @@ -1289,5 +1299,13 @@ func Define( // nolint:revive // function-length versionCmdRoot, whoamiCmdRoot, aliasPurge, + aliasServiceVersionActivate, + aliasServiceVersionClone, + aliasServiceVersionDeactivate, + aliasServiceVersionList, + aliasServiceVersionLock, + aliasServiceVersionStage, + aliasServiceVersionUnstage, + aliasServiceVersionUpdate, } } diff --git a/pkg/commands/serviceversion/activate.go b/pkg/commands/service/version/activate.go similarity index 99% rename from pkg/commands/serviceversion/activate.go rename to pkg/commands/service/version/activate.go index b5c453093..348cba5b8 100644 --- a/pkg/commands/serviceversion/activate.go +++ b/pkg/commands/service/version/activate.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/clone.go b/pkg/commands/service/version/clone.go similarity index 99% rename from pkg/commands/serviceversion/clone.go rename to pkg/commands/service/version/clone.go index a2bf5b22d..ae9bff152 100644 --- a/pkg/commands/serviceversion/clone.go +++ b/pkg/commands/service/version/clone.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/deactivate.go b/pkg/commands/service/version/deactivate.go similarity index 99% rename from pkg/commands/serviceversion/deactivate.go rename to pkg/commands/service/version/deactivate.go index 00db8754c..bece5f5e2 100644 --- a/pkg/commands/serviceversion/deactivate.go +++ b/pkg/commands/service/version/deactivate.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/service/version/doc.go b/pkg/commands/service/version/doc.go new file mode 100644 index 000000000..44a0111a3 --- /dev/null +++ b/pkg/commands/service/version/doc.go @@ -0,0 +1,3 @@ +// Package version contains commands to inspect and manipulate Fastly +// service versions. +package version diff --git a/pkg/commands/serviceversion/list.go b/pkg/commands/service/version/list.go similarity index 99% rename from pkg/commands/serviceversion/list.go rename to pkg/commands/service/version/list.go index eafeac44b..2d56d4b31 100644 --- a/pkg/commands/serviceversion/list.go +++ b/pkg/commands/service/version/list.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/lock.go b/pkg/commands/service/version/lock.go similarity index 99% rename from pkg/commands/serviceversion/lock.go rename to pkg/commands/service/version/lock.go index 65ec36ed2..c4fb8e1b2 100644 --- a/pkg/commands/serviceversion/lock.go +++ b/pkg/commands/service/version/lock.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/service/version/root.go b/pkg/commands/service/version/root.go new file mode 100644 index 000000000..dd6d4d012 --- /dev/null +++ b/pkg/commands/service/version/root.go @@ -0,0 +1,31 @@ +package version + +import ( + "io" + + "github.com/fastly/cli/pkg/argparser" + "github.com/fastly/cli/pkg/global" +) + +// RootCommand is the parent command for all subcommands in this package. +// It should be installed under the primary root command. +type RootCommand struct { + argparser.Base + // no flags +} + +// CommandName is the string to be used to invoke this command. +const CommandName = "version" + +// NewRootCommand returns a new command registered in the parent. +func NewRootCommand(parent argparser.Registerer, g *global.Data) *RootCommand { + var c RootCommand + c.Globals = g + c.CmdClause = parent.Command(CommandName, "Manipulate Fastly service versions") + return &c +} + +// Exec implements the command interface. +func (c *RootCommand) Exec(_ io.Reader, _ io.Writer) error { + panic("unreachable") +} diff --git a/pkg/commands/serviceversion/serviceversion_test.go b/pkg/commands/service/version/serviceversion_test.go similarity index 93% rename from pkg/commands/serviceversion/serviceversion_test.go rename to pkg/commands/service/version/serviceversion_test.go index 53d5ae7cf..340718b92 100644 --- a/pkg/commands/serviceversion/serviceversion_test.go +++ b/pkg/commands/service/version/serviceversion_test.go @@ -1,4 +1,4 @@ -package serviceversion_test +package version_test import ( "context" @@ -7,7 +7,8 @@ import ( "github.com/fastly/go-fastly/v12/fastly" - root "github.com/fastly/cli/pkg/commands/serviceversion" + root "github.com/fastly/cli/pkg/commands/service" + sub "github.com/fastly/cli/pkg/commands/service/version" "github.com/fastly/cli/pkg/mock" "github.com/fastly/cli/pkg/testutil" ) @@ -53,7 +54,7 @@ func TestVersionClone(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "clone"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "clone"}, scenarios) } func TestVersionList(t *testing.T) { @@ -90,7 +91,7 @@ func TestVersionList(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "list"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "list"}, scenarios) } func TestVersionUpdate(t *testing.T) { @@ -123,7 +124,7 @@ func TestVersionUpdate(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "update"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "update"}, scenarios) } func TestVersionActivate(t *testing.T) { @@ -176,7 +177,7 @@ func TestVersionActivate(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "activate"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "activate"}, scenarios) } func TestVersionDeactivate(t *testing.T) { @@ -211,7 +212,7 @@ func TestVersionDeactivate(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "deactivate"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "deactivate"}, scenarios) } func TestVersionLock(t *testing.T) { @@ -238,7 +239,7 @@ func TestVersionLock(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "lock"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "lock"}, scenarios) } func TestVersionStage(t *testing.T) { @@ -289,7 +290,7 @@ func TestVersionStage(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "stage"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "stage"}, scenarios) } func TestVersionUnstage(t *testing.T) { @@ -332,7 +333,7 @@ func TestVersionUnstage(t *testing.T) { }, } - testutil.RunCLIScenarios(t, []string{root.CommandName, "unstage"}, scenarios) + testutil.RunCLIScenarios(t, []string{root.CommandName, sub.CommandName, "unstage"}, scenarios) } var cloneServiceVersionJSONOutput = strings.TrimSpace(` diff --git a/pkg/commands/serviceversion/stage.go b/pkg/commands/service/version/stage.go similarity index 99% rename from pkg/commands/serviceversion/stage.go rename to pkg/commands/service/version/stage.go index 0fa5f1363..17a65808b 100644 --- a/pkg/commands/serviceversion/stage.go +++ b/pkg/commands/service/version/stage.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/unstage.go b/pkg/commands/service/version/unstage.go similarity index 99% rename from pkg/commands/serviceversion/unstage.go rename to pkg/commands/service/version/unstage.go index 098b30f2b..29f47ebb7 100644 --- a/pkg/commands/serviceversion/unstage.go +++ b/pkg/commands/service/version/unstage.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/update.go b/pkg/commands/service/version/update.go similarity index 99% rename from pkg/commands/serviceversion/update.go rename to pkg/commands/service/version/update.go index 884bd1d01..199e2ff86 100644 --- a/pkg/commands/serviceversion/update.go +++ b/pkg/commands/service/version/update.go @@ -1,4 +1,4 @@ -package serviceversion +package version import ( "context" diff --git a/pkg/commands/serviceversion/doc.go b/pkg/commands/serviceversion/doc.go deleted file mode 100644 index c556fa239..000000000 --- a/pkg/commands/serviceversion/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package serviceversion contains commands to inspect and manipulate Fastly -// service versions. -package serviceversion