diff --git a/internal/commands/account/account.go b/internal/commands/account/account.go index 2cab39d7c..64b2e3986 100644 --- a/internal/commands/account/account.go +++ b/internal/commands/account/account.go @@ -12,3 +12,8 @@ func BaseAccountCommand() commands.Command { type accountCommand struct { *commands.BaseCommand } + +// InitCommand implements Command.InitCommand +func (acc *accountCommand) InitCommand() { + acc.Cobra().Aliases = []string{"acc"} +} diff --git a/internal/commands/gateway/gateway.go b/internal/commands/gateway/gateway.go index 1db955eb3..c5339be85 100644 --- a/internal/commands/gateway/gateway.go +++ b/internal/commands/gateway/gateway.go @@ -14,3 +14,8 @@ func BaseGatewayCommand() commands.Command { type gatewayCommand struct { *commands.BaseCommand } + +// InitCommand implements Command.InitCommand +func (gw *gatewayCommand) InitCommand() { + gw.Cobra().Aliases = []string{"gw"} +} diff --git a/internal/commands/kubernetes/config.go b/internal/commands/kubernetes/config.go index a6da035ae..339a4fd01 100644 --- a/internal/commands/kubernetes/config.go +++ b/internal/commands/kubernetes/config.go @@ -46,10 +46,18 @@ func (c *configCommand) InitCommand() { "", "Absolute path for writing output. If the file exists, the config will be merged.") c.AddFlags(flagSet) + + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"k8s"}) } // Execute implements commands.MultipleArgumentCommand func (c *configCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"k8s"}, "uks") + svc := exec.All() msg := fmt.Sprintf("Getting kubeconfig for Kubernetes cluster %s", uuid) diff --git a/internal/commands/kubernetes/create.go b/internal/commands/kubernetes/create.go index deb67bfdb..70b0d377d 100644 --- a/internal/commands/kubernetes/create.go +++ b/internal/commands/kubernetes/create.go @@ -152,6 +152,10 @@ func (c *createCommand) InitCommand() { commands.Must(c.Cobra().MarkFlagRequired("network")) commands.Must(c.Cobra().MarkFlagRequired("zone")) commands.Must(c.Cobra().RegisterFlagCompletionFunc("name", cobra.NoFileCompletions)) + + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"k8s"}) } func (c *createCommand) InitCommandWithConfig(cfg *config.Config) { @@ -162,6 +166,10 @@ func (c *createCommand) InitCommandWithConfig(cfg *config.Config) { // ExecuteWithoutArguments implements commands.NoArgumentCommand func (c *createCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"k8s"}, "uks") + svc := exec.All() if err := c.params.processParams(exec); err != nil { diff --git a/internal/commands/kubernetes/delete.go b/internal/commands/kubernetes/delete.go index fb1a1f1e6..3cb118d4d 100644 --- a/internal/commands/kubernetes/delete.go +++ b/internal/commands/kubernetes/delete.go @@ -29,8 +29,19 @@ type deleteCommand struct { completion.Kubernetes } +// InitCommand implements Command.InitCommand +func (s *deleteCommand) InitCommand() { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"k8s"}) +} + // Execute implements commands.MultipleArgumentCommand func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"k8s"}, "uks") + svc := exec.All() msg := fmt.Sprintf("Deleting Kubernetes cluster %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/kubernetes/kubernetes.go b/internal/commands/kubernetes/kubernetes.go index 75d40148a..df7763c29 100644 --- a/internal/commands/kubernetes/kubernetes.go +++ b/internal/commands/kubernetes/kubernetes.go @@ -18,4 +18,7 @@ type kubernetesCommand struct { // InitCommand implements Command.InitCommand func (k *kubernetesCommand) InitCommand() { k.Cobra().Aliases = []string{"k8s", "uks"} + // Deprecating k8s + // TODO: Remove this in the future + commands.SetDeprecationHelp(k.Cobra(), []string{"k8s"}) } diff --git a/internal/commands/kubernetes/list.go b/internal/commands/kubernetes/list.go index dfc3c014d..f6794f5f2 100644 --- a/internal/commands/kubernetes/list.go +++ b/internal/commands/kubernetes/list.go @@ -20,8 +20,19 @@ type listCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (s *listCommand) InitCommand() { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"k8s"}) +} + // ExecuteWithoutArguments implements commands.NoArgumentCommand func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"k8s"}, "uks") + svc := exec.All() clusters, err := svc.GetKubernetesClusters(exec.Context(), &request.GetKubernetesClustersRequest{}) if err != nil { diff --git a/internal/commands/kubernetes/modify.go b/internal/commands/kubernetes/modify.go index c05931ca2..fc41e3b35 100644 --- a/internal/commands/kubernetes/modify.go +++ b/internal/commands/kubernetes/modify.go @@ -52,10 +52,18 @@ func (c *modifyCommand) InitCommand() { c.AddFlags(fs) c.Cobra().MarkFlagsMutuallyExclusive("label", "clear-labels") commands.Must(c.Cobra().RegisterFlagCompletionFunc("label", cobra.NoFileCompletions)) + + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"k8s"}) } // Execute implements commands.MultipleArgumentCommand func (c *modifyCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"k8s"}, "uks") + msg := fmt.Sprintf("Modifying Kubernetes cluster %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/kubernetes/plans.go b/internal/commands/kubernetes/plans.go index 596c80107..92baec48f 100644 --- a/internal/commands/kubernetes/plans.go +++ b/internal/commands/kubernetes/plans.go @@ -17,8 +17,19 @@ type plansCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (s *plansCommand) InitCommand() { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"k8s"}) +} + // Execute implements commands.NoArgumentCommand func (s *plansCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"k8s"}, "uks") + svc := exec.All() plans, err := svc.GetKubernetesPlans(exec.Context(), &request.GetKubernetesPlansRequest{}) if err != nil { diff --git a/internal/commands/kubernetes/show.go b/internal/commands/kubernetes/show.go index d27158e83..de21b94b0 100644 --- a/internal/commands/kubernetes/show.go +++ b/internal/commands/kubernetes/show.go @@ -34,8 +34,19 @@ type showCommand struct { completion.Kubernetes } +// InitCommand implements Command.InitCommand +func (s *showCommand) InitCommand() { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"k8s"}) +} + // Execute implements commands.MultipleArgumentCommand func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"k8s"}, "uks") + svc := exec.All() cluster, err := svc.GetKubernetesCluster(exec.Context(), &request.GetKubernetesClusterRequest{UUID: uuid}) if err != nil { diff --git a/internal/commands/kubernetes/versions.go b/internal/commands/kubernetes/versions.go index 8d0dc6df4..e4e1f9dcb 100644 --- a/internal/commands/kubernetes/versions.go +++ b/internal/commands/kubernetes/versions.go @@ -18,8 +18,19 @@ type versionsCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (s *versionsCommand) InitCommand() { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"k8s"}) +} + // ExecuteWithoutArguments implements commands.NoArgumentCommand func (s *versionsCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating k8s + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"k8s"}, "uks") + svc := exec.All() versions, err := svc.GetKubernetesVersions(exec.Context(), &request.GetKubernetesVersionsRequest{}) if err != nil { diff --git a/internal/commands/loadbalancer/delete.go b/internal/commands/loadbalancer/delete.go index 10fcb99e2..a2972e4f3 100644 --- a/internal/commands/loadbalancer/delete.go +++ b/internal/commands/loadbalancer/delete.go @@ -16,8 +16,8 @@ func DeleteCommand() commands.Command { BaseCommand: commands.New( "delete", "Delete a load balancer", - "upctl loadbalancer delete 55199a44-4751-4e27-9394-7c7661910be3", - "upctl loadbalancer delete my-load-balancer", + "upctl load-balancer delete 55199a44-4751-4e27-9394-7c7661910be3", + "upctl load-balancer delete my-load-balancer", ), } } @@ -28,8 +28,18 @@ type deleteCommand struct { completion.LoadBalancer } +func (s *deleteCommand) InitCommand() { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"loadbalancer"}) +} + // Execute implements commands.MultipleArgumentCommand func (s *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"loadbalancer"}, "load-balancer") + svc := exec.All() msg := fmt.Sprintf("Deleting load balancer %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/loadbalancer/list.go b/internal/commands/loadbalancer/list.go index 8bc9b17b3..74083a9ea 100644 --- a/internal/commands/loadbalancer/list.go +++ b/internal/commands/loadbalancer/list.go @@ -12,9 +12,11 @@ import ( // ListCommand creates the "loadbalancer list" command func ListCommand() commands.Command { - return &listCommand{ - BaseCommand: commands.New("list", "List current load balancers", "upctl loadbalancer list"), + cmd := &listCommand{ + BaseCommand: commands.New("list", "List current load balancers", "upctl load-balancer list"), } + + return cmd } type listCommand struct { @@ -26,10 +28,16 @@ func (s *listCommand) InitCommand() { fs := &pflag.FlagSet{} s.ConfigureFlags(fs) s.AddFlags(fs) + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"loadbalancer"}) } // ExecuteWithoutArguments implements commands.NoArgumentCommand func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"loadbalancer"}, "load-balancer") svc := exec.All() loadbalancers, err := svc.GetLoadBalancers(exec.Context(), &request.GetLoadBalancersRequest{ Page: s.Page(), diff --git a/internal/commands/loadbalancer/loadbalancer.go b/internal/commands/loadbalancer/loadbalancer.go index 72d858b77..a8dc06f5b 100644 --- a/internal/commands/loadbalancer/loadbalancer.go +++ b/internal/commands/loadbalancer/loadbalancer.go @@ -7,7 +7,7 @@ import ( // BaseLoadBalancerCommand creates the base "loadbalancer" command func BaseLoadBalancerCommand() commands.Command { return &loadbalancerCommand{ - commands.New("loadbalancer", "Manage load balancers"), + commands.New("load-balancer", "Manage load balancers"), } } @@ -17,5 +17,9 @@ type loadbalancerCommand struct { // InitCommand implements Command.InitCommand func (lb *loadbalancerCommand) InitCommand() { - lb.Cobra().Aliases = []string{"lb"} + lb.Cobra().Aliases = []string{"lb", "loadbalancer"} + + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetDeprecationHelp(lb.Cobra(), []string{"loadbalancer"}) } diff --git a/internal/commands/loadbalancer/plans.go b/internal/commands/loadbalancer/plans.go index be4a11a49..d6fe6c2ab 100644 --- a/internal/commands/loadbalancer/plans.go +++ b/internal/commands/loadbalancer/plans.go @@ -9,7 +9,7 @@ import ( // PlansCommand creates the "loadbalancer plans" command func PlansCommand() commands.Command { return &plansCommand{ - BaseCommand: commands.New("plans", "List available load balancer plans", "upctl loadbalancer plans"), + BaseCommand: commands.New("plans", "List available load balancer plans", "upctl load-balancer plans"), } } @@ -17,8 +17,18 @@ type plansCommand struct { *commands.BaseCommand } +func (s *plansCommand) InitCommand() { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"loadbalancer"}) +} + // Execute implements commands.NoArgumentCommand func (s *plansCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"loadbalancer"}, "load-balancer") + svc := exec.All() plans, err := svc.GetLoadBalancerPlans(exec.Context(), &request.GetLoadBalancerPlansRequest{}) if err != nil { diff --git a/internal/commands/loadbalancer/show.go b/internal/commands/loadbalancer/show.go index 444da87a1..a88f366b5 100644 --- a/internal/commands/loadbalancer/show.go +++ b/internal/commands/loadbalancer/show.go @@ -20,8 +20,8 @@ func ShowCommand() commands.Command { BaseCommand: commands.New( "show", "Show load balancer details", - "upctl loadbalancer show 55199a44-4751-4e27-9394-7c7661910be3", - "upctl loadbalancer show my-load-balancer", + "upctl load-balancer show 55199a44-4751-4e27-9394-7c7661910be3", + "upctl load-balancer show my-load-balancer", ), } } @@ -32,8 +32,18 @@ type showCommand struct { completion.LoadBalancer } +func (s *showCommand) InitCommand() { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"loadbalancer"}) +} + // Execute implements commands.MultipleArgumentCommand func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating loadbalancer in favour of load-balancer + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"loadbalancer"}, "load-balancer") + svc := exec.All() lb, err := svc.GetLoadBalancer(exec.Context(), &request.GetLoadBalancerRequest{UUID: uuid}) if err != nil { diff --git a/internal/commands/networkpeering/delete.go b/internal/commands/networkpeering/delete.go index 7c5f5b1d8..8bf2dac52 100644 --- a/internal/commands/networkpeering/delete.go +++ b/internal/commands/networkpeering/delete.go @@ -17,8 +17,8 @@ func DeleteCommand() commands.Command { BaseCommand: commands.New( "delete", "Delete a network peering", - "upctl networkpeering delete 8abc8009-4325-4b23-4321-b1232cd81231", - "upctl networkpeering delete my-network-peering", + "upctl network-peering delete 8abc8009-4325-4b23-4321-b1232cd81231", + "upctl network-peering delete my-network-peering", ), } } @@ -29,8 +29,19 @@ type deleteCommand struct { completion.NetworkPeering } +// InitCommand implements Command.InitCommand +func (c *deleteCommand) InitCommand() { + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"networkpeering"}) +} + // Execute implements commands.MultipleArgumentCommand func (c *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"networkpeering"}, "network-peering") + svc := exec.All() msg := fmt.Sprintf("Deleting network peering %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/networkpeering/disable.go b/internal/commands/networkpeering/disable.go index 1a47fcb3d..37379a966 100644 --- a/internal/commands/networkpeering/disable.go +++ b/internal/commands/networkpeering/disable.go @@ -20,8 +20,8 @@ func DisableCommand() commands.Command { BaseCommand: commands.New( "disable", "Disable a network peering", - "upctl networkpeering disable 8abc8009-4325-4b23-4321-b1232cd81231", - "upctl networkpeering disable my-network-peering", + "upctl network-peering disable 8abc8009-4325-4b23-4321-b1232cd81231", + "upctl network-peering disable my-network-peering", ), } } @@ -39,10 +39,17 @@ func (c *disableCommand) InitCommand() { flags := &pflag.FlagSet{} config.AddToggleFlag(flags, &c.wait, "wait", false, "Wait for network peering to be in disabled state before returning.") c.AddFlags(flags) + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"networkpeering"}) } // Execute implements commands.MultipleArgumentCommand func (c *disableCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"networkpeering"}, "network-peering") + svc := exec.All() msg := fmt.Sprintf("Disabling network peering %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/networkpeering/list.go b/internal/commands/networkpeering/list.go index df1c2d7fb..0492773fc 100644 --- a/internal/commands/networkpeering/list.go +++ b/internal/commands/networkpeering/list.go @@ -10,7 +10,7 @@ import ( // ListCommand creates the "networkpeering list" command func ListCommand() commands.Command { return &listCommand{ - BaseCommand: commands.New("list", "List network peerings", "upctl networkpeering list"), + BaseCommand: commands.New("list", "List network peerings", "upctl network-peering list"), } } @@ -18,8 +18,18 @@ type listCommand struct { *commands.BaseCommand } +func (c *listCommand) InitCommand() { + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"networkpeering"}) +} + // ExecuteWithoutArguments implements commands.NoArgumentCommand func (c *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"networkpeering"}, "network-peering") + svc := exec.All() peerings, err := svc.GetNetworkPeerings(exec.Context()) if err != nil { diff --git a/internal/commands/networkpeering/networkpeering.go b/internal/commands/networkpeering/networkpeering.go index 12d5d7a2d..24789f9c9 100644 --- a/internal/commands/networkpeering/networkpeering.go +++ b/internal/commands/networkpeering/networkpeering.go @@ -14,7 +14,7 @@ import ( // BaseNetworkPeeringCommand creates the base "networkpeering" command func BaseNetworkPeeringCommand() commands.Command { return &networkpeeringCommand{ - commands.New("networkpeering", "Manage network peerings"), + commands.New("network-peering", "Manage network peerings"), } } @@ -22,6 +22,14 @@ type networkpeeringCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (np *networkpeeringCommand) InitCommand() { + np.Cobra().Aliases = []string{"np", "networkpeering"} + // Deprecating networkpeering in favour of network-peering + // TODO: Remove this in the future + commands.SetDeprecationHelp(np.Cobra(), []string{"networkpeering"}) +} + // waitForNetworkPeeringState waits for network peering to reach given state and updates progress message with key matching given msg. Finally, progress message is updated back to given msg and either done state or timeout warning. func waitForNetworkPeeringState(uuid string, state upcloud.NetworkPeeringState, exec commands.Executor, msg string) { exec.PushProgressUpdateMessage(msg, fmt.Sprintf("Waiting for network peering %s to be in %s state", uuid, state)) diff --git a/internal/commands/objectstorage/delete.go b/internal/commands/objectstorage/delete.go index 2b5504f76..e38d0d6d2 100644 --- a/internal/commands/objectstorage/delete.go +++ b/internal/commands/objectstorage/delete.go @@ -42,10 +42,18 @@ func (c *deleteCommand) InitCommand() { config.AddToggleFlag(flags, &c.deletePolicies, "delete-policies", false, "Delete all policies from the service before deleting the object storage instance.") config.AddToggleFlag(flags, &c.deleteBuckets, "delete-buckets", false, "Delete all buckets from the service before deleting the object storage instance.") c.AddFlags(flags) + + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"objectstorage", "objsto"}) } // Execute implements commands.MultipleArgumentCommand func (c *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"objectstorage", "objsto"}, "object-storage") + svc := exec.All() msg := fmt.Sprintf("Deleting object storage service %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/objectstorage/list.go b/internal/commands/objectstorage/list.go index 84d6dc570..a6178e4d1 100644 --- a/internal/commands/objectstorage/list.go +++ b/internal/commands/objectstorage/list.go @@ -14,7 +14,7 @@ import ( // ListCommand creates the "objectstorage list" command func ListCommand() commands.Command { return &listCommand{ - BaseCommand: commands.New("list", "List current Managed object storage services", "upctl objectstorage list"), + BaseCommand: commands.New("list", "List current Managed object storage services", "upctl object-storage list"), } } @@ -27,10 +27,18 @@ func (c *listCommand) InitCommand() { fs := &pflag.FlagSet{} c.ConfigureFlags(fs) c.AddFlags(fs) + + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"objectstorage", "objsto"}) } // ExecuteWithoutArguments implements commands.NoArgumentCommand func (c *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"objectstorage", "objsto"}, "object-storage") + svc := exec.All() objectstorages, err := svc.GetManagedObjectStorages(exec.Context(), &request.GetManagedObjectStoragesRequest{ Page: c.Page(), diff --git a/internal/commands/objectstorage/objectstorage.go b/internal/commands/objectstorage/objectstorage.go index 2e23db9fc..4e1d62ab9 100644 --- a/internal/commands/objectstorage/objectstorage.go +++ b/internal/commands/objectstorage/objectstorage.go @@ -4,10 +4,10 @@ import ( "github.com/UpCloudLtd/upcloud-cli/v3/internal/commands" ) -// BaseobjectstorageCommand creates the base "objectstorage" command +// BaseobjectstorageCommand creates the base "object-storage" command func BaseobjectstorageCommand() commands.Command { return &objectstorageCommand{ - commands.New("objectstorage", "Manage managed object storage services"), + commands.New("object-storage", "Manage managed object storage services"), } } @@ -17,5 +17,9 @@ type objectstorageCommand struct { // InitCommand implements Command.InitCommand func (c *objectstorageCommand) InitCommand() { - c.Cobra().Aliases = []string{"object-storage", "objsto"} + c.Cobra().Aliases = []string{"obs", "objectstorage", "objsto"} + + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetDeprecationHelp(c.Cobra(), []string{"objectstorage", "objsto"}) } diff --git a/internal/commands/objectstorage/regions.go b/internal/commands/objectstorage/regions.go index 59923f295..2063ef8b4 100644 --- a/internal/commands/objectstorage/regions.go +++ b/internal/commands/objectstorage/regions.go @@ -20,8 +20,18 @@ type regionsCommand struct { *commands.BaseCommand } +func (s *regionsCommand) InitCommand() { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(s, []string{"objectstorage", "objsto"}) +} + // ExecuteWithoutArguments implements commands.NoArgumentCommand func (s *regionsCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(s, []string{"objectstorage", "objsto"}, "object-storage") + regions, err := exec.All().GetManagedObjectStorageRegions(exec.Context(), &request.GetManagedObjectStorageRegionsRequest{}) if err != nil { return nil, err diff --git a/internal/commands/objectstorage/show.go b/internal/commands/objectstorage/show.go index f7a78f34c..e0f3f5af4 100644 --- a/internal/commands/objectstorage/show.go +++ b/internal/commands/objectstorage/show.go @@ -28,8 +28,18 @@ type showCommand struct { completion.ObjectStorage } +func (c *showCommand) InitCommand() { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"objectstorage", "objsto"}) +} + // Execute implements commands.MultipleArgumentCommand func (c *showCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating objectstorage and objsto in favour of object-storage + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"objectstorage", "objsto"}, "object-storage") + svc := exec.All() objectStorage, err := svc.GetManagedObjectStorage(exec.Context(), &request.GetManagedObjectStorageRequest{UUID: uuid}) if err != nil { diff --git a/internal/commands/partner/partner.go b/internal/commands/partner/partner.go index f0e11420b..050730571 100644 --- a/internal/commands/partner/partner.go +++ b/internal/commands/partner/partner.go @@ -14,3 +14,8 @@ func BasePartnerCommand() commands.Command { type partnerCommand struct { *commands.BaseCommand } + +// InitCommand implements Command.InitCommand +func (pr *partnerCommand) InitCommand() { + pr.Cobra().Aliases = []string{"pr"} +} diff --git a/internal/commands/router/router.go b/internal/commands/router/router.go index ee2cfc350..7a5465e7f 100644 --- a/internal/commands/router/router.go +++ b/internal/commands/router/router.go @@ -16,3 +16,8 @@ func BaseRouterCommand() commands.Command { type routerCommand struct { *commands.BaseCommand } + +// InitCommand implements Command.InitCommand +func (rt *routerCommand) InitCommand() { + rt.Cobra().Aliases = []string{"rt"} +} diff --git a/internal/commands/server/server.go b/internal/commands/server/server.go index 9d3412059..3a7440c5e 100644 --- a/internal/commands/server/server.go +++ b/internal/commands/server/server.go @@ -34,6 +34,11 @@ type serverCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (srv *serverCommand) InitCommand() { + srv.Cobra().Aliases = []string{"srv"} +} + // waitForServerState waits for server to reach given state and updates progress message with key matching given msg. Finally, progress message is updated back to given msg and either done state or timeout warning. func waitForServerState(uuid, state string, exec commands.Executor, msg string) { exec.PushProgressUpdateMessage(msg, fmt.Sprintf("Waiting for server %s to be in %s state", uuid, state)) diff --git a/internal/commands/servergroup/create.go b/internal/commands/servergroup/create.go index b5cda69f3..af89b162a 100644 --- a/internal/commands/servergroup/create.go +++ b/internal/commands/servergroup/create.go @@ -23,16 +23,16 @@ func CreateCommand() commands.Command { BaseCommand: commands.New( "create", "Create a server group", - `upctl servergroup create \ + `upctl server-group create \ --title my-server-group \ --anti-affinity-policy yes \ --server 1fdfda29-ead1-4855-b71f-a432179800ab \ --server my-server`, - `upctl servergroup create \ + `upctl server-group create \ --title my-server-group \ --anti-affinity-policy yes \ --label env=dev`, - `upctl servergroup create \ + `upctl server-group create \ --title my-server-group \ --anti-affinity-policy strict \ --label env=dev \ @@ -97,6 +97,10 @@ func (c *createCommand) InitCommand() { commands.Must(c.Cobra().MarkFlagRequired("title")) commands.Must(c.Cobra().RegisterFlagCompletionFunc("title", cobra.NoFileCompletions)) commands.Must(c.Cobra().RegisterFlagCompletionFunc("label", cobra.NoFileCompletions)) + + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"servergroup"}) } func (c *createCommand) InitCommandWithConfig(cfg *config.Config) { @@ -105,6 +109,10 @@ func (c *createCommand) InitCommandWithConfig(cfg *config.Config) { // ExecuteWithoutArguments implements commands.NoArgumentCommand func (c *createCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"servergroup"}, "server-group") + svc := exec.All() if err := c.params.processParams(exec); err != nil { diff --git a/internal/commands/servergroup/delete.go b/internal/commands/servergroup/delete.go index 581d04a0f..ffa4ec936 100644 --- a/internal/commands/servergroup/delete.go +++ b/internal/commands/servergroup/delete.go @@ -17,8 +17,8 @@ func DeleteCommand() commands.Command { BaseCommand: commands.New( "delete", "Delete a server group", - "upctl servergroup delete 8abc8009-4325-4b23-4321-b1232cd81231", - "upctl servergroup delete my-server-group", + "upctl server-group delete 8abc8009-4325-4b23-4321-b1232cd81231", + "upctl server-group delete my-server-group", ), } } @@ -29,8 +29,19 @@ type deleteCommand struct { completion.ServerGroup } +// InitCommand implements Command.InitCommand +func (c *deleteCommand) InitCommand() { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"servergroup"}) +} + // Execute implements commands.MultipleArgumentCommand func (c *deleteCommand) Execute(exec commands.Executor, arg string) (output.Output, error) { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"servergroup"}, "server-group") + svc := exec.All() msg := fmt.Sprintf("Deleting server group %v", arg) exec.PushProgressStarted(msg) diff --git a/internal/commands/servergroup/list.go b/internal/commands/servergroup/list.go index 309b735ec..44550f932 100644 --- a/internal/commands/servergroup/list.go +++ b/internal/commands/servergroup/list.go @@ -13,7 +13,7 @@ import ( // ListCommand creates the "servergroup list" command func ListCommand() commands.Command { return &listCommand{ - BaseCommand: commands.New("list", "List current server groups", "upctl servergroup list"), + BaseCommand: commands.New("list", "List current server groups", "upctl server-group list"), } } @@ -21,8 +21,19 @@ type listCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (c *listCommand) InitCommand() { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"servergroup"}) +} + // ExecuteWithoutArguments implements commands.NoArgumentCommand func (c *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Output, error) { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"servergroup"}, "server-group") + svc := exec.All() serverGroups, err := svc.GetServerGroups(exec.Context(), &request.GetServerGroupsRequest{}) if err != nil { diff --git a/internal/commands/servergroup/modify.go b/internal/commands/servergroup/modify.go index f4942de85..ccdfa29ad 100644 --- a/internal/commands/servergroup/modify.go +++ b/internal/commands/servergroup/modify.go @@ -30,11 +30,11 @@ func ModifyCommand() commands.Command { BaseCommand: commands.New( "modify", "Modify a server group", - "upctl servergroup modify 8abc8009-4325-4b23-4321-b1232cd81231 --title your-server-group", - "upctl servergroup modify my-server-group --anti-affinity-policy strict", - `upctl servergroup modify my-server-group --server my-server-1 --server my-server-2 --server my-server-3-`, - `upctl servergroup modify 8abc8009-4325-4b23-4321-b1232cd81231 --server 0bab98e5-b327-4ab8-ba16-738d4af7578b --server my-server-2`, - `upctl servergroup modify my-server-group --label env=dev`, + "upctl server-group modify 8abc8009-4325-4b23-4321-b1232cd81231 --title your-server-group", + "upctl server-group modify my-server-group --anti-affinity-policy strict", + `upctl server-group modify my-server-group --server my-server-1 --server my-server-2 --server my-server-3-`, + `upctl server-group modify 8abc8009-4325-4b23-4321-b1232cd81231 --server 0bab98e5-b327-4ab8-ba16-738d4af7578b --server my-server-2`, + `upctl server-group modify my-server-group --label env=dev`, ), } } @@ -89,6 +89,10 @@ func (c *modifyCommand) InitCommand() { c.AddFlags(fs) commands.Must(c.Cobra().RegisterFlagCompletionFunc("title", cobra.NoFileCompletions)) commands.Must(c.Cobra().RegisterFlagCompletionFunc("label", cobra.NoFileCompletions)) + + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"servergroup"}) } func (c *modifyCommand) InitCommandWithConfig(cfg *config.Config) { @@ -97,6 +101,10 @@ func (c *modifyCommand) InitCommandWithConfig(cfg *config.Config) { // Execute implements commands.MultipleArgumentCommand func (c *modifyCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"servergroup"}, "server-group") + svc := exec.All() err := c.params.processParams(exec, uuid) diff --git a/internal/commands/servergroup/servergroup.go b/internal/commands/servergroup/servergroup.go index 6e7128b6b..9758679e3 100644 --- a/internal/commands/servergroup/servergroup.go +++ b/internal/commands/servergroup/servergroup.go @@ -15,7 +15,7 @@ const ( // BaseServergroupCommand creates the base "servergroup" command func BaseServergroupCommand() commands.Command { return &servergroupCommand{ - commands.New("servergroup", "Manage server groups"), + commands.New("server-group", "Manage server groups"), } } @@ -23,6 +23,14 @@ type servergroupCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (sg *servergroupCommand) InitCommand() { + sg.Cobra().Aliases = []string{"sg", "servergroup"} + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetDeprecationHelp(sg.Cobra(), []string{"servergroup"}) +} + func stringsToServerUUIDSlice(exec commands.Executor, servers []string) (upcloud.ServerUUIDSlice, error) { slice := make(upcloud.ServerUUIDSlice, 0) for _, v := range servers { diff --git a/internal/commands/servergroup/show.go b/internal/commands/servergroup/show.go index 3314db5fe..21e76a689 100644 --- a/internal/commands/servergroup/show.go +++ b/internal/commands/servergroup/show.go @@ -21,8 +21,8 @@ func ShowCommand() commands.Command { BaseCommand: commands.New( "show", "Show server group details", - "upctl servergroup show 8abc8009-4325-4b23-4321-b1232cd81231", - "upctl servergroup show my-server-group", + "upctl server-group show 8abc8009-4325-4b23-4321-b1232cd81231", + "upctl server-group show my-server-group", ), } } @@ -33,8 +33,19 @@ type showCommand struct { completion.ServerGroup } +// InitCommand implements Command.InitCommand +func (c *showCommand) InitCommand() { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandDeprecationHelp(c, []string{"servergroup"}) +} + // Execute implements commands.MultipleArgumentCommand func (c *showCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { + // Deprecating servergroup in favour of server-group + // TODO: Remove this in the future + commands.SetSubcommandExecutionDeprecationMessage(c, []string{"servergroup"}, "server-group") + svc := exec.All() serverGroup, err := svc.GetServerGroup(exec.Context(), &request.GetServerGroupRequest{UUID: uuid}) if err != nil { diff --git a/internal/commands/storage/storage.go b/internal/commands/storage/storage.go index c2ee63c84..0c8765006 100644 --- a/internal/commands/storage/storage.go +++ b/internal/commands/storage/storage.go @@ -30,6 +30,11 @@ type storageCommand struct { *commands.BaseCommand } +// InitCommand implements Command.InitCommand +func (st *storageCommand) InitCommand() { + st.Cobra().Aliases = []string{"st"} +} + func matchStorages(storages []upcloud.Storage, searchVal string) []*upcloud.Storage { var r []*upcloud.Storage for _, storage := range storages { diff --git a/internal/commands/util.go b/internal/commands/util.go index 1f1461a2e..a52726a24 100644 --- a/internal/commands/util.go +++ b/internal/commands/util.go @@ -7,9 +7,11 @@ import ( "os" "reflect" "regexp" + "slices" "strings" "github.com/UpCloudLtd/upcloud-cli/v3/internal/validation" + "github.com/spf13/cobra" "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud" "github.com/jedib0t/go-pretty/v6/text" @@ -141,6 +143,115 @@ func ParseSSHKeys(sshKeys []string) ([]string, error) { return allSSHKeys, nil } +// SetDeprecationHelp hides a specific alias in the help output and prints a deprecation warning when used. +// Only works for primary commands, not subcommands. +func SetDeprecationHelp(cmd *cobra.Command, deprecatedAliases []string) { + // Construct new alias list, excluding the deprecated aliases + var filteredAliases []string + for _, alias := range cmd.Aliases { + if !slices.Contains(deprecatedAliases, alias) { // ✅ Using slices.Contains + filteredAliases = append(filteredAliases, alias) + } + } + + // Update the alias list in the usage template **before** help is triggered + originalTemplate := cmd.UsageTemplate() + var modifiedTemplate string + + if len(filteredAliases) > 0 { + modifiedTemplate = strings.ReplaceAll(originalTemplate, "{{.NameAndAliases}}{{end}}", "{{.Use}}, "+strings.Join(filteredAliases, ", ")+"{{end}}") + } else { + modifiedTemplate = strings.ReplaceAll(originalTemplate, "{{.NameAndAliases}}{{end}}", "{{.Use}}{{end}}") + } + + // Apply the updated usage template **before help is called** + cmd.SetUsageTemplate(modifiedTemplate) + + // Custom Help Function to Show Deprecation Warning + cmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) { + if slices.Contains(deprecatedAliases, cmd.CalledAs()) { + PrintDeprecationWarning(cmd.CalledAs(), cmd.Use) + } + + // Print the help output with the modified alias list + fmt.Println(cmd.UsageString()) + }) + + // Intercept help execution using PersistentPreRunE + originalPreRunE := cmd.PersistentPreRunE + + // Show deprecation message when upctl help is called + cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { + // Call the parent command's PersistentPreRunE first + if cmd.Parent() != nil && cmd.Parent().PersistentPreRunE != nil { + if err := cmd.Parent().PersistentPreRunE(cmd.Parent(), args); err != nil { + return err + } + } + + // Show deprecation warning if the alias was used + if slices.Contains(deprecatedAliases, cmd.CalledAs()) { + PrintDeprecationWarning(cmd.CalledAs(), cmd.Use) + } + + // Call the original PersistentPreRunE (if defined) + if originalPreRunE != nil { + return originalPreRunE(cmd, args) + } + + return nil + } +} + +// SetSubcommandDeprecationHelp detects the correct interface implementation and wraps the relevant execution function. +func SetSubcommandDeprecationHelp(cmd Command, aliases []string) { + // Set a custom help function to display the warning for `-h` or `--help` + cobraCmd := cmd.Cobra() + originalHelpFunc := cobraCmd.HelpFunc() + cobraCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { + for _, alias := range aliases { + if IsDeprecatedAliasUsed(alias) { + PrintDeprecationWarning(alias, cmd.Parent().Use) + break + } + } + originalHelpFunc(cmd, args) + }) +} + +// isDeprecatedAliasUsed checks if the deprecated alias was used in the command invocation +func IsDeprecatedAliasUsed(deprecatedAlias string) bool { + if len(os.Args) < 2 { + return false + } + + for _, arg := range os.Args[1:] { + if arg == deprecatedAlias { + return true + } + } + return false +} + +// PrintDeprecationWarning prints a deprecation message +func PrintDeprecationWarning(deprecatedAlias, newCommand string) { + fmt.Fprintf(os.Stderr, "⚠️ Deprecation Warning: The alias '%s' is deprecated and will be removed in a future release.\n", deprecatedAlias) + fmt.Fprintf(os.Stderr, " Please use '%s' instead.\n", newCommand) +} + +func SetSubcommandExecutionDeprecationMessage(cmd Command, deprecatedParentAliases []string, mainParentAlias string) { + parentCmd := cmd.Cobra().Parent() + if parentCmd != nil { + for _, deprecatedParentAlias := range deprecatedParentAliases { + // Check if the parent was called using the deprecated alias + if IsDeprecatedAliasUsed(deprecatedParentAlias) { + PrintDeprecationWarning(deprecatedParentAlias, mainParentAlias) + break + } + } + } +} + // Must panics if the error is not nil. func Must(err error) { if err != nil {