Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add consistent aliases #362

Merged
merged 8 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/commands/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
5 changes: 5 additions & 0 deletions internal/commands/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
8 changes: 8 additions & 0 deletions internal/commands/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions internal/commands/kubernetes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions internal/commands/kubernetes/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/commands/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}
11 changes: 11 additions & 0 deletions internal/commands/kubernetes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions internal/commands/kubernetes/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions internal/commands/kubernetes/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions internal/commands/kubernetes/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions internal/commands/kubernetes/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions internal/commands/loadbalancer/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions internal/commands/loadbalancer/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand Down
8 changes: 6 additions & 2 deletions internal/commands/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand All @@ -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"})
}
12 changes: 11 additions & 1 deletion internal/commands/loadbalancer/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ 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"),
}
}

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 {
Expand Down
14 changes: 12 additions & 2 deletions internal/commands/loadbalancer/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}
Expand All @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions internal/commands/networkpeering/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions internal/commands/networkpeering/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
}
}
Expand All @@ -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)
Expand Down
Loading