diff --git a/internal/cmd/all/all.go b/internal/cmd/all/all.go index 871820762..1fde6f3b1 100644 --- a/internal/cmd/all/all.go +++ b/internal/cmd/all/all.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "all", Short: "Commands that apply to all resources", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/base/delete.go b/internal/cmd/base/delete.go index 4b2af6ee3..838a05efd 100644 --- a/internal/cmd/base/delete.go +++ b/internal/cmd/base/delete.go @@ -34,7 +34,7 @@ func (dc *DeleteCmd) CobraCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s<%s>", opts, strings.ToLower(dc.ResourceNameSingular)), Short: dc.ShortDescription, - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/base/describe.go b/internal/cmd/base/describe.go index b3ec51067..3ac581fbd 100644 --- a/internal/cmd/base/describe.go +++ b/internal/cmd/base/describe.go @@ -35,7 +35,7 @@ func (dc *DescribeCmd) CobraCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe [options] <%s>", strings.ToLower(dc.ResourceNameSingular)), Short: dc.ShortDescription, - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/base/set_rdns.go b/internal/cmd/base/set_rdns.go index df8d157fa..1bf1ba3cc 100644 --- a/internal/cmd/base/set_rdns.go +++ b/internal/cmd/base/set_rdns.go @@ -30,7 +30,7 @@ func (rc *SetRdnsCmd) CobraCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("set-rdns [options] <%s> --hostname ", strings.ToLower(rc.ResourceNameSingular)), Short: rc.ShortDescription, - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(rc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/base/update.go b/internal/cmd/base/update.go index a40f2373b..4b4c3f72b 100644 --- a/internal/cmd/base/update.go +++ b/internal/cmd/base/update.go @@ -30,7 +30,7 @@ func (uc *UpdateCmd) CobraCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update [options] <%s>", strings.ToLower(uc.ResourceNameSingular)), Short: uc.ShortDescription, - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(uc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/certificate/certificate.go b/internal/cmd/certificate/certificate.go index 121c09d00..55747d684 100644 --- a/internal/cmd/certificate/certificate.go +++ b/internal/cmd/certificate/certificate.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "certificate", Short: "Manage certificates", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/certificate/create.go b/internal/cmd/certificate/create.go index 81420b9df..96cc59cbe 100644 --- a/internal/cmd/certificate/create.go +++ b/internal/cmd/certificate/create.go @@ -19,7 +19,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name (--type managed | --type uploaded --cert-file --key-file )", Short: "Create or upload a Certificate", - Args: util.Validate, + Args: util.ValidateExact, } cmd.Flags().String("name", "", "Certificate name (required)") diff --git a/internal/cmd/completion/completion.go b/internal/cmd/completion/completion.go index e068adaa4..ee622feeb 100644 --- a/internal/cmd/completion/completion.go +++ b/internal/cmd/completion/completion.go @@ -95,7 +95,7 @@ and source this file from your PowerShell profile. PS> hcloud completion powershell > hcloud.ps1 `, - Args: util.Validate, + Args: util.ValidateExact, ValidArgs: []string{"bash", "fish", "zsh", "powershell"}, DisableFlagsInUseLine: true, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/cmd/context/active.go b/internal/cmd/context/active.go index ea3e4065c..49566e6ca 100644 --- a/internal/cmd/context/active.go +++ b/internal/cmd/context/active.go @@ -14,7 +14,7 @@ func newActiveCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "active", Short: "Show active context", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, RunE: state.Wrap(s, runActive), diff --git a/internal/cmd/context/context.go b/internal/cmd/context/context.go index f5c020b4a..e7d73da7d 100644 --- a/internal/cmd/context/context.go +++ b/internal/cmd/context/context.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "context", Short: "Manage contexts", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/context/create.go b/internal/cmd/context/create.go index f013797fd..82cef48bf 100644 --- a/internal/cmd/context/create.go +++ b/internal/cmd/context/create.go @@ -20,7 +20,7 @@ func newCreateCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "create ", Short: "Create a new context", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, RunE: state.Wrap(s, runCreate), diff --git a/internal/cmd/context/delete.go b/internal/cmd/context/delete.go index 56a77530e..aaa181d39 100644 --- a/internal/cmd/context/delete.go +++ b/internal/cmd/context/delete.go @@ -16,7 +16,7 @@ func newDeleteCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "delete ", Short: "Delete a context", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidates(config.ContextNames(s.Config())...)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/context/list.go b/internal/cmd/context/list.go index a1b191b5f..6cb351820 100644 --- a/internal/cmd/context/list.go +++ b/internal/cmd/context/list.go @@ -30,7 +30,7 @@ func newListCommand(s state.State) *cobra.Command { "Displays a list of contexts.", listTableOutput.Columns(), ), - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, RunE: state.Wrap(s, runList), diff --git a/internal/cmd/context/use.go b/internal/cmd/context/use.go index 6dbf0d646..e94aee596 100644 --- a/internal/cmd/context/use.go +++ b/internal/cmd/context/use.go @@ -16,7 +16,7 @@ func newUseCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "use ", Short: "Use a context", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidates(config.ContextNames(s.Config())...)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/datacenter/datacenter.go b/internal/cmd/datacenter/datacenter.go index 3e21df038..ebfc89c83 100644 --- a/internal/cmd/datacenter/datacenter.go +++ b/internal/cmd/datacenter/datacenter.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "datacenter", Short: "Manage datacenters", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/firewall/add_rule.go b/internal/cmd/firewall/add_rule.go index c5d0d4d78..58180e88c 100644 --- a/internal/cmd/firewall/add_rule.go +++ b/internal/cmd/firewall/add_rule.go @@ -19,7 +19,7 @@ var AddRuleCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-rule [options] (--direction in --source-ips | --direction out --destination-ips ) --protocol ", Short: "Add a single rule to a firewall", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Firewall().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/firewall/apply_to_resource.go b/internal/cmd/firewall/apply_to_resource.go index e2ec82f56..4f1a0f8f6 100644 --- a/internal/cmd/firewall/apply_to_resource.go +++ b/internal/cmd/firewall/apply_to_resource.go @@ -18,7 +18,7 @@ var ApplyToResourceCmd = base.Cmd{ cmd := &cobra.Command{ Use: "apply-to-resource (--type server --server | --type label_selector --label-selector )", Short: "Applies a Firewall to a single resource", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Firewall().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/firewall/create.go b/internal/cmd/firewall/create.go index b43e4d769..31bd59c40 100644 --- a/internal/cmd/firewall/create.go +++ b/internal/cmd/firewall/create.go @@ -22,7 +22,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name ", Short: "Create a Firewall", - Args: util.Validate, + Args: util.ValidateExact, } cmd.Flags().String("name", "", "Name") cmd.MarkFlagRequired("name") diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 2d6ccc43a..203f4e8c9 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -20,7 +20,7 @@ var DeleteRuleCmd = base.Cmd{ cmd := &cobra.Command{ Use: "delete-rule [options] (--direction in --source-ips | --direction out --destination-ips ) --protocol ", Short: "Delete a single rule to a firewall", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Firewall().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/firewall/firewall.go b/internal/cmd/firewall/firewall.go index 393d97a5b..923d90cd1 100644 --- a/internal/cmd/firewall/firewall.go +++ b/internal/cmd/firewall/firewall.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "firewall", Short: "Manage Firewalls", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/firewall/remove_from_resource.go b/internal/cmd/firewall/remove_from_resource.go index 926f6c3a3..efe6c6465 100644 --- a/internal/cmd/firewall/remove_from_resource.go +++ b/internal/cmd/firewall/remove_from_resource.go @@ -18,7 +18,7 @@ var RemoveFromResourceCmd = base.Cmd{ cmd := &cobra.Command{ Use: "remove-from-resource (--type server --server | --type label_selector --label-selector )", Short: "Removes a Firewall from a single resource", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Firewall().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/firewall/replace_rules.go b/internal/cmd/firewall/replace_rules.go index bd6d96eb2..221ae3dd4 100644 --- a/internal/cmd/firewall/replace_rules.go +++ b/internal/cmd/firewall/replace_rules.go @@ -23,7 +23,7 @@ var ReplaceRulesCmd = base.Cmd{ cmd := &cobra.Command{ Use: "replace-rules --rules-file ", Short: "Replaces all rules from a Firewall from a file", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Firewall().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/floatingip/assign.go b/internal/cmd/floatingip/assign.go index 692d383d5..69e0a3f13 100644 --- a/internal/cmd/floatingip/assign.go +++ b/internal/cmd/floatingip/assign.go @@ -17,7 +17,7 @@ var AssignCmd = base.Cmd{ return &cobra.Command{ Use: "assign ", Short: "Assign a Floating IP to a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.FloatingIP().Names), cmpl.SuggestCandidatesF(client.Server().Names), diff --git a/internal/cmd/floatingip/create.go b/internal/cmd/floatingip/create.go index 0a0fa1d97..eebb077d0 100644 --- a/internal/cmd/floatingip/create.go +++ b/internal/cmd/floatingip/create.go @@ -19,7 +19,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --type (--home-location | --server )", Short: "Create a Floating IP", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/floatingip/floatingip.go b/internal/cmd/floatingip/floatingip.go index 67d6e636e..b7dd74e1f 100644 --- a/internal/cmd/floatingip/floatingip.go +++ b/internal/cmd/floatingip/floatingip.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "floating-ip", Short: "Manage Floating IPs", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/floatingip/unassign.go b/internal/cmd/floatingip/unassign.go index bc6bead5d..d062a65a0 100644 --- a/internal/cmd/floatingip/unassign.go +++ b/internal/cmd/floatingip/unassign.go @@ -17,7 +17,7 @@ var UnassignCmd = base.Cmd{ return &cobra.Command{ Use: "unassign ", Short: "Unassign a Floating IP", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.FloatingIP().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/image/image.go b/internal/cmd/image/image.go index 028468dea..b03477ab1 100644 --- a/internal/cmd/image/image.go +++ b/internal/cmd/image/image.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "image", Short: "Manage images", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/iso/iso.go b/internal/cmd/iso/iso.go index ea51f822c..ab695bf22 100644 --- a/internal/cmd/iso/iso.go +++ b/internal/cmd/iso/iso.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "iso", Short: "Manage ISOs", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/loadbalancer/add_service.go b/internal/cmd/loadbalancer/add_service.go index 7122f287d..39573ef51 100644 --- a/internal/cmd/loadbalancer/add_service.go +++ b/internal/cmd/loadbalancer/add_service.go @@ -18,7 +18,7 @@ var AddServiceCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-service [options] (--protocol http | --protocol tcp --listen-port <1-65535> --destination-port <1-65535> | --protocol https --http-certificates )", Short: "Add a service to a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/add_target.go b/internal/cmd/loadbalancer/add_target.go index 0ef6aa8c1..dea6b0b65 100644 --- a/internal/cmd/loadbalancer/add_target.go +++ b/internal/cmd/loadbalancer/add_target.go @@ -19,7 +19,7 @@ var AddTargetCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-target [options] ", Short: "Add a target to a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/attach_to_network.go b/internal/cmd/loadbalancer/attach_to_network.go index 4a2639f26..8cdd1b260 100644 --- a/internal/cmd/loadbalancer/attach_to_network.go +++ b/internal/cmd/loadbalancer/attach_to_network.go @@ -18,7 +18,7 @@ var AttachToNetworkCmd = base.Cmd{ cmd := &cobra.Command{ Use: "attach-to-network [--ip ] --network ", Short: "Attach a Load Balancer to a Network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/change_algorithm.go b/internal/cmd/loadbalancer/change_algorithm.go index 2dc716bd3..c1839887f 100644 --- a/internal/cmd/loadbalancer/change_algorithm.go +++ b/internal/cmd/loadbalancer/change_algorithm.go @@ -18,7 +18,7 @@ var ChangeAlgorithmCmd = base.Cmd{ cmd := &cobra.Command{ Use: "change-algorithm --algorithm-type ", Short: "Changes the algorithm of a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/change_type.go b/internal/cmd/loadbalancer/change_type.go index ec864c376..a6075659f 100644 --- a/internal/cmd/loadbalancer/change_type.go +++ b/internal/cmd/loadbalancer/change_type.go @@ -18,7 +18,7 @@ var ChangeTypeCmd = base.Cmd{ return &cobra.Command{ Use: "change-type ", Short: "Change type of a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.LoadBalancer().Names), cmpl.SuggestCandidatesF(client.LoadBalancerType().Names), diff --git a/internal/cmd/loadbalancer/create.go b/internal/cmd/loadbalancer/create.go index b86498962..6d58ae1b7 100644 --- a/internal/cmd/loadbalancer/create.go +++ b/internal/cmd/loadbalancer/create.go @@ -16,7 +16,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name --type ", Short: "Create a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/loadbalancer/detach_from_network.go b/internal/cmd/loadbalancer/detach_from_network.go index 17e97c0f7..fd5de4d20 100644 --- a/internal/cmd/loadbalancer/detach_from_network.go +++ b/internal/cmd/loadbalancer/detach_from_network.go @@ -18,7 +18,7 @@ var DetachFromNetworkCmd = base.Cmd{ cmd := &cobra.Command{ Use: "detach-from-network --network ", Short: "Detach a Load Balancer from a Network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/disable_public_interface.go b/internal/cmd/loadbalancer/disable_public_interface.go index 635cb6f09..c14fa4dfe 100644 --- a/internal/cmd/loadbalancer/disable_public_interface.go +++ b/internal/cmd/loadbalancer/disable_public_interface.go @@ -17,7 +17,7 @@ var DisablePublicInterfaceCmd = base.Cmd{ return &cobra.Command{ Use: "disable-public-interface [options] ", Short: "Disable the public interface of a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/enable_public_interface.go b/internal/cmd/loadbalancer/enable_public_interface.go index 41f0de10d..c39f88165 100644 --- a/internal/cmd/loadbalancer/enable_public_interface.go +++ b/internal/cmd/loadbalancer/enable_public_interface.go @@ -17,7 +17,7 @@ var EnablePublicInterfaceCmd = base.Cmd{ return &cobra.Command{ Use: "enable-public-interface ", Short: "Enable the public interface of a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/load_balancer.go b/internal/cmd/loadbalancer/load_balancer.go index ca3b20d2b..a0b70f9e6 100644 --- a/internal/cmd/loadbalancer/load_balancer.go +++ b/internal/cmd/loadbalancer/load_balancer.go @@ -12,7 +12,7 @@ func NewCommand(s state.State) *cobra.Command { Use: "load-balancer", Short: "Manage Load Balancers", Aliases: []string{"loadbalancer"}, - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/loadbalancer/metrics.go b/internal/cmd/loadbalancer/metrics.go index a9bce7ea7..b21b137b1 100644 --- a/internal/cmd/loadbalancer/metrics.go +++ b/internal/cmd/loadbalancer/metrics.go @@ -33,7 +33,7 @@ var MetricsCmd = base.Cmd{ cmd := &cobra.Command{ Use: fmt.Sprintf("metrics [options] --type <%s>", strings.Join(metricTypeStrings, "|")), Short: "[ALPHA] Metrics from a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/remove_target.go b/internal/cmd/loadbalancer/remove_target.go index 062314dd9..0ec85a747 100644 --- a/internal/cmd/loadbalancer/remove_target.go +++ b/internal/cmd/loadbalancer/remove_target.go @@ -19,7 +19,7 @@ var RemoveTargetCmd = base.Cmd{ cmd := &cobra.Command{ Use: "remove-target [options] ", Short: "Remove a target from a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancer/update_service.go b/internal/cmd/loadbalancer/update_service.go index 1997607cc..20b7537b4 100644 --- a/internal/cmd/loadbalancer/update_service.go +++ b/internal/cmd/loadbalancer/update_service.go @@ -19,7 +19,7 @@ var UpdateServiceCmd = base.Cmd{ cmd := &cobra.Command{ Use: "update-service [options] --listen-port <1-65535>", Short: "Updates a service from a Load Balancer", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.LoadBalancer().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/loadbalancertype/load_balancer_type.go b/internal/cmd/loadbalancertype/load_balancer_type.go index afc160064..85445140c 100644 --- a/internal/cmd/loadbalancertype/load_balancer_type.go +++ b/internal/cmd/loadbalancertype/load_balancer_type.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "load-balancer-type", Short: "Manage Load Balancer types", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/location/location.go b/internal/cmd/location/location.go index 80acec9ad..2cfb3e6be 100644 --- a/internal/cmd/location/location.go +++ b/internal/cmd/location/location.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "location", Short: "Manage locations", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/network/add_route.go b/internal/cmd/network/add_route.go index 568e67c76..ec895c80b 100644 --- a/internal/cmd/network/add_route.go +++ b/internal/cmd/network/add_route.go @@ -19,7 +19,7 @@ var AddRouteCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-route --destination --gateway ", Short: "Add a route to a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/network/add_subnet.go b/internal/cmd/network/add_subnet.go index 849069ce0..938647b7b 100644 --- a/internal/cmd/network/add_subnet.go +++ b/internal/cmd/network/add_subnet.go @@ -19,7 +19,7 @@ var AddSubnetCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-subnet [options] --type --network-zone ", Short: "Add a subnet to a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/network/change_ip_range.go b/internal/cmd/network/change_ip_range.go index 493fab704..0e568d852 100644 --- a/internal/cmd/network/change_ip_range.go +++ b/internal/cmd/network/change_ip_range.go @@ -19,7 +19,7 @@ var ChangeIPRangeCmd = base.Cmd{ cmd := &cobra.Command{ Use: "change-ip-range --ip-range ", Short: "Change the IP range of a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/network/create.go b/internal/cmd/network/create.go index a42e055d5..2436061f3 100644 --- a/internal/cmd/network/create.go +++ b/internal/cmd/network/create.go @@ -18,7 +18,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name --ip-range ", Short: "Create a network", - Args: util.Validate, + Args: util.ValidateExact, } cmd.Flags().String("name", "", "Network name (required)") diff --git a/internal/cmd/network/expose_routes_to_vswitch.go b/internal/cmd/network/expose_routes_to_vswitch.go index cd9ed5baf..cbe737575 100644 --- a/internal/cmd/network/expose_routes_to_vswitch.go +++ b/internal/cmd/network/expose_routes_to_vswitch.go @@ -19,7 +19,7 @@ var ExposeRoutesToVSwitchCmd = base.Cmd{ Use: "expose-routes-to-vswitch [--disable] ", Short: "Expose routes to connected vSwitch", Long: "Enabling this will expose routes to the connected vSwitch. Set the --disable flag to remove the exposed routes.", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/network/network.go b/internal/cmd/network/network.go index 9f3965539..0e0860fb9 100644 --- a/internal/cmd/network/network.go +++ b/internal/cmd/network/network.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "network", Short: "Manage networks", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/network/remove_route.go b/internal/cmd/network/remove_route.go index 001c6ee33..7ac077c9f 100644 --- a/internal/cmd/network/remove_route.go +++ b/internal/cmd/network/remove_route.go @@ -19,7 +19,7 @@ var RemoveRouteCmd = base.Cmd{ cmd := &cobra.Command{ Use: "remove-route --destination --gateway ", Short: "Remove a route from a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/network/remove_subnet.go b/internal/cmd/network/remove_subnet.go index 3f27febea..6b174aa90 100644 --- a/internal/cmd/network/remove_subnet.go +++ b/internal/cmd/network/remove_subnet.go @@ -19,7 +19,7 @@ var RemoveSubnetCmd = base.Cmd{ cmd := &cobra.Command{ Use: "remove-subnet --ip-range ", Short: "Remove a subnet from a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Network().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/placementgroup/placementgroup.go b/internal/cmd/placementgroup/placementgroup.go index f54277b17..8baed0ce6 100644 --- a/internal/cmd/placementgroup/placementgroup.go +++ b/internal/cmd/placementgroup/placementgroup.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "placement-group", Short: "Manage Placement Groups", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/primaryip/assign.go b/internal/cmd/primaryip/assign.go index 0b6f47eb5..c8be344a4 100644 --- a/internal/cmd/primaryip/assign.go +++ b/internal/cmd/primaryip/assign.go @@ -18,7 +18,7 @@ var AssignCmd = base.Cmd{ cmd := &cobra.Command{ Use: "assign --server ", Short: "Assign a Primary IP to an assignee (usually a server)", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.PrimaryIP().Names), ), diff --git a/internal/cmd/primaryip/create.go b/internal/cmd/primaryip/create.go index 141091f28..13a7181b5 100644 --- a/internal/cmd/primaryip/create.go +++ b/internal/cmd/primaryip/create.go @@ -16,7 +16,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --type --name ", Short: "Create a Primary IP", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/primaryip/primaryip.go b/internal/cmd/primaryip/primaryip.go index e3ea80cfb..e0a344a1c 100644 --- a/internal/cmd/primaryip/primaryip.go +++ b/internal/cmd/primaryip/primaryip.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "primary-ip", Short: "Manage Primary IPs", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/primaryip/unassign.go b/internal/cmd/primaryip/unassign.go index 3c6620768..749f4f0f8 100644 --- a/internal/cmd/primaryip/unassign.go +++ b/internal/cmd/primaryip/unassign.go @@ -17,7 +17,7 @@ var UnAssignCmd = base.Cmd{ cmd := &cobra.Command{ Use: "unassign ", Short: "Unassign a Primary IP from an assignee (usually a server)", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.PrimaryIP().Names), ), diff --git a/internal/cmd/server/add_to_placement_group.go b/internal/cmd/server/add_to_placement_group.go index 68acb590f..91866eed4 100644 --- a/internal/cmd/server/add_to_placement_group.go +++ b/internal/cmd/server/add_to_placement_group.go @@ -17,7 +17,7 @@ var AddToPlacementGroupCmd = base.Cmd{ cmd := &cobra.Command{ Use: "add-to-placement-group --placement-group ", Short: "Add a server to a placement group", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), } diff --git a/internal/cmd/server/attach_iso.go b/internal/cmd/server/attach_iso.go index e6fe3071a..638f64065 100644 --- a/internal/cmd/server/attach_iso.go +++ b/internal/cmd/server/attach_iso.go @@ -18,7 +18,7 @@ var AttachISOCmd = base.Cmd{ return &cobra.Command{ Use: "attach-iso ", Short: "Attach an ISO to a server", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.Server().Names), diff --git a/internal/cmd/server/attach_to_network.go b/internal/cmd/server/attach_to_network.go index 6549d0e69..6bed36190 100644 --- a/internal/cmd/server/attach_to_network.go +++ b/internal/cmd/server/attach_to_network.go @@ -19,7 +19,7 @@ var AttachToNetworkCmd = base.Cmd{ cmd := &cobra.Command{ Use: "attach-to-network [options] --network ", Short: "Attach a server to a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/change_alias_ips.go b/internal/cmd/server/change_alias_ips.go index 5e96aa66b..88d47bd5f 100644 --- a/internal/cmd/server/change_alias_ips.go +++ b/internal/cmd/server/change_alias_ips.go @@ -19,7 +19,7 @@ var ChangeAliasIPsCmd = base.Cmd{ cmd := &cobra.Command{ Use: "change-alias-ips [options] --network ", Short: "Change a server's alias IPs in a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/change_type.go b/internal/cmd/server/change_type.go index 290235f6a..6d143b202 100644 --- a/internal/cmd/server/change_type.go +++ b/internal/cmd/server/change_type.go @@ -18,7 +18,7 @@ var ChangeTypeCmd = base.Cmd{ cmd := &cobra.Command{ Use: "change-type [--keep-disk] ", Short: "Change type of a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.Server().Names), cmpl.SuggestCandidatesF(client.ServerType().Names), diff --git a/internal/cmd/server/create_image.go b/internal/cmd/server/create_image.go index f7474d1b9..83fe0d8f5 100644 --- a/internal/cmd/server/create_image.go +++ b/internal/cmd/server/create_image.go @@ -18,7 +18,7 @@ var CreateImageCmd = base.Cmd{ cmd := &cobra.Command{ Use: "create-image [options] ", Short: "Create an image from a server", - Args: util.Validate, + Args: util.ValidateExact, } cmd.Flags().String("type", "", "Image type (required)") cmd.RegisterFlagCompletionFunc("type", cmpl.SuggestCandidates("backup", "snapshot")) diff --git a/internal/cmd/server/detach_from_network.go b/internal/cmd/server/detach_from_network.go index 7c94d5108..7b81e455c 100644 --- a/internal/cmd/server/detach_from_network.go +++ b/internal/cmd/server/detach_from_network.go @@ -18,7 +18,7 @@ var DetachFromNetworkCmd = base.Cmd{ cmd := &cobra.Command{ Use: "detach-from-network --network ", Short: "Detach a server from a network", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/detach_iso.go b/internal/cmd/server/detach_iso.go index d80f6d35a..7ba772bc4 100644 --- a/internal/cmd/server/detach_iso.go +++ b/internal/cmd/server/detach_iso.go @@ -17,7 +17,7 @@ var DetachISOCmd = base.Cmd{ return &cobra.Command{ Use: "detach-iso ", Short: "Detach an ISO from a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/disable_backup.go b/internal/cmd/server/disable_backup.go index e8369e5b6..7a0d64494 100644 --- a/internal/cmd/server/disable_backup.go +++ b/internal/cmd/server/disable_backup.go @@ -17,7 +17,7 @@ var DisableBackupCmd = base.Cmd{ return &cobra.Command{ Use: "disable-backup ", Short: "Disable backup for a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/disable_rescue.go b/internal/cmd/server/disable_rescue.go index 043000d76..8ed96bbbf 100644 --- a/internal/cmd/server/disable_rescue.go +++ b/internal/cmd/server/disable_rescue.go @@ -17,7 +17,7 @@ var DisableRescueCmd = base.Cmd{ return &cobra.Command{ Use: "disable-rescue ", Short: "Disable rescue for a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/enable_backup.go b/internal/cmd/server/enable_backup.go index bee3316a8..00f929417 100644 --- a/internal/cmd/server/enable_backup.go +++ b/internal/cmd/server/enable_backup.go @@ -17,7 +17,7 @@ var EnableBackupCmd = base.Cmd{ cmd := &cobra.Command{ Use: "enable-backup ", Short: "Enable backup for a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/enable_rescue.go b/internal/cmd/server/enable_rescue.go index 233382bcf..49b7fe0bd 100644 --- a/internal/cmd/server/enable_rescue.go +++ b/internal/cmd/server/enable_rescue.go @@ -18,7 +18,7 @@ var EnableRescueCmd = base.Cmd{ cmd := &cobra.Command{ Use: "enable-rescue [options] ", Short: "Enable rescue for a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/ip.go b/internal/cmd/server/ip.go index eef0544dd..8e91c14ad 100644 --- a/internal/cmd/server/ip.go +++ b/internal/cmd/server/ip.go @@ -17,7 +17,7 @@ var IPCmd = base.Cmd{ cmd := &cobra.Command{ Use: "ip [--ipv6] ", Short: "Print a server's IP address", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/metrics.go b/internal/cmd/server/metrics.go index 698b16cf1..67bf288a7 100644 --- a/internal/cmd/server/metrics.go +++ b/internal/cmd/server/metrics.go @@ -31,7 +31,7 @@ var MetricsCmd = base.Cmd{ cmd := &cobra.Command{ Use: "metrics [options] ", Short: "[ALPHA] Metrics from a Server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/poweroff.go b/internal/cmd/server/poweroff.go index 92b13cc3b..0a6b7c07e 100644 --- a/internal/cmd/server/poweroff.go +++ b/internal/cmd/server/poweroff.go @@ -17,7 +17,7 @@ var PoweroffCmd = base.Cmd{ return &cobra.Command{ Use: "poweroff ", Short: "Poweroff a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/poweron.go b/internal/cmd/server/poweron.go index d203f2e60..2e6cd1d75 100644 --- a/internal/cmd/server/poweron.go +++ b/internal/cmd/server/poweron.go @@ -17,7 +17,7 @@ var PoweronCmd = base.Cmd{ return &cobra.Command{ Use: "poweron ", Short: "Poweron a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/reboot.go b/internal/cmd/server/reboot.go index ef2c73e44..aeae1cc22 100644 --- a/internal/cmd/server/reboot.go +++ b/internal/cmd/server/reboot.go @@ -17,7 +17,7 @@ var RebootCmd = base.Cmd{ return &cobra.Command{ Use: "reboot ", Short: "Reboot a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/rebuild.go b/internal/cmd/server/rebuild.go index b096bed5a..1a533c13d 100644 --- a/internal/cmd/server/rebuild.go +++ b/internal/cmd/server/rebuild.go @@ -19,7 +19,7 @@ var RebuildCmd = base.Cmd{ cmd := &cobra.Command{ Use: "rebuild [--allow-deprecated-image] --image ", Short: "Rebuild a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/remove_from_placement_group.go b/internal/cmd/server/remove_from_placement_group.go index 04e0b306d..a1415ed21 100644 --- a/internal/cmd/server/remove_from_placement_group.go +++ b/internal/cmd/server/remove_from_placement_group.go @@ -17,7 +17,7 @@ var RemoveFromPlacementGroupCmd = base.Cmd{ cmd := &cobra.Command{ Use: "remove-from-placement-group ", Short: "Removes a server from a placement group", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), } diff --git a/internal/cmd/server/request_console.go b/internal/cmd/server/request_console.go index 2cb02be4a..18862344d 100644 --- a/internal/cmd/server/request_console.go +++ b/internal/cmd/server/request_console.go @@ -18,7 +18,7 @@ var RequestConsoleCmd = base.Cmd{ cmd := &cobra.Command{ Use: "request-console [options] ", Short: "Request a WebSocket VNC console for a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/reset.go b/internal/cmd/server/reset.go index 6dbd21355..5c36ca9ad 100644 --- a/internal/cmd/server/reset.go +++ b/internal/cmd/server/reset.go @@ -17,7 +17,7 @@ var ResetCmd = base.Cmd{ return &cobra.Command{ Use: "reset [options] ", Short: "Reset a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/reset_password.go b/internal/cmd/server/reset_password.go index e8185eabe..f1ad38058 100644 --- a/internal/cmd/server/reset_password.go +++ b/internal/cmd/server/reset_password.go @@ -17,7 +17,7 @@ var ResetPasswordCmd = base.Cmd{ return &cobra.Command{ Use: "reset-password ", Short: "Reset the root password of a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/server.go b/internal/cmd/server/server.go index 48adcf6c4..a4c234a73 100644 --- a/internal/cmd/server/server.go +++ b/internal/cmd/server/server.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "server", Short: "Manage servers", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/server/shutdown.go b/internal/cmd/server/shutdown.go index 6a4c7a17f..4f25340ce 100644 --- a/internal/cmd/server/shutdown.go +++ b/internal/cmd/server/shutdown.go @@ -27,7 +27,7 @@ var ShutdownCmd = base.Cmd{ Use: "shutdown [options] ", Short: "Shutdown a server", Long: description, - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/server/ssh.go b/internal/cmd/server/ssh.go index 090905f5d..21b98db01 100644 --- a/internal/cmd/server/ssh.go +++ b/internal/cmd/server/ssh.go @@ -21,7 +21,7 @@ var SSHCmd = base.Cmd{ cmd := &cobra.Command{ Use: "ssh [options] [command]", Short: "Spawn an SSH connection for the server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Server().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/servertype/server_type.go b/internal/cmd/servertype/server_type.go index 7a35bde8b..1eecfba84 100644 --- a/internal/cmd/servertype/server_type.go +++ b/internal/cmd/servertype/server_type.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "server-type", Short: "Manage server types", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/sshkey/create.go b/internal/cmd/sshkey/create.go index 5512114bc..b17b1f6ea 100644 --- a/internal/cmd/sshkey/create.go +++ b/internal/cmd/sshkey/create.go @@ -18,7 +18,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name (--public-key | --public-key-from-file )", Short: "Create a SSH key", - Args: util.Validate, + Args: util.ValidateExact, } cmd.Flags().String("name", "", "Key name (required)") _ = cmd.MarkFlagRequired("name") diff --git a/internal/cmd/sshkey/sshkey.go b/internal/cmd/sshkey/sshkey.go index db94e14a8..5e3b79984 100644 --- a/internal/cmd/sshkey/sshkey.go +++ b/internal/cmd/sshkey/sshkey.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "ssh-key", Short: "Manage SSH keys", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/util/validation.go b/internal/cmd/util/validation.go index 6acd45132..c9069159e 100644 --- a/internal/cmd/util/validation.go +++ b/internal/cmd/util/validation.go @@ -11,7 +11,15 @@ import ( var posArgRegex = regexp.MustCompile(`\[.*?]|\(.*?\)|--.*?<.*?>|<(.*?)>`) // matches all positional args in group 1 +func ValidateExact(cmd *cobra.Command, args []string) error { + return validate(cmd, args, true) +} + func Validate(cmd *cobra.Command, args []string) error { + return validate(cmd, args, false) +} + +func validate(cmd *cobra.Command, args []string, exact bool) error { matches := posArgRegex.FindAllStringSubmatch(cmd.Use, -1) var expected []string for _, match := range matches { @@ -19,7 +27,7 @@ func Validate(cmd *cobra.Command, args []string) error { expected = append(expected, match[1]) } } - if len(args) > len(expected) { + if len(args) > len(expected) && exact { return fmt.Errorf("expected exactly %d positional arguments, but got %d", len(expected), len(args)) } for i := 0; i < len(expected); i++ { @@ -29,7 +37,7 @@ func Validate(cmd *cobra.Command, args []string) error { _, _ = fmt.Fprintln(os.Stderr, cmd.Use) _, _ = fmt.Fprintln(os.Stderr, strings.Repeat(" ", idx+1)+strings.Repeat("^", len(expected[i]))) } - return fmt.Errorf("expected argument %s at position %d", strings.ReplaceAll(expected[i], "-", " "), i+1) + return fmt.Errorf("expected argument %s at position %d", expected[i], i+1) } } return nil diff --git a/internal/cmd/version/version.go b/internal/cmd/version/version.go index 48a1d1f30..3bca97b63 100644 --- a/internal/cmd/version/version.go +++ b/internal/cmd/version/version.go @@ -12,7 +12,7 @@ func NewCommand(_ state.State) *cobra.Command { cmd := &cobra.Command{ Use: "version", Short: "Print version information", - Args: util.Validate, + Args: util.ValidateExact, DisableFlagsInUseLine: true, RunE: runVersion, } diff --git a/internal/cmd/volume/attach.go b/internal/cmd/volume/attach.go index df691cd70..d1afdaee5 100644 --- a/internal/cmd/volume/attach.go +++ b/internal/cmd/volume/attach.go @@ -18,7 +18,7 @@ var AttachCmd = base.Cmd{ cmd := &cobra.Command{ Use: "attach [--automount] --server ", Short: "Attach a volume to a server", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Volume().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/volume/create.go b/internal/cmd/volume/create.go index b0c2e4c38..a83d92679 100644 --- a/internal/cmd/volume/create.go +++ b/internal/cmd/volume/create.go @@ -19,7 +19,7 @@ var CreateCmd = base.CreateCmd{ cmd := &cobra.Command{ Use: "create [options] --name --size ", Short: "Create a volume", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, } diff --git a/internal/cmd/volume/detach.go b/internal/cmd/volume/detach.go index 3b41a602c..87643c98e 100644 --- a/internal/cmd/volume/detach.go +++ b/internal/cmd/volume/detach.go @@ -17,7 +17,7 @@ var DetachCmd = base.Cmd{ return &cobra.Command{ Use: "detach ", Short: "Detach a volume", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Volume().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/volume/resize.go b/internal/cmd/volume/resize.go index be5fbd228..c7a3ca15d 100644 --- a/internal/cmd/volume/resize.go +++ b/internal/cmd/volume/resize.go @@ -17,7 +17,7 @@ var ResizeCmd = base.Cmd{ cmd := &cobra.Command{ Use: "resize --size ", Short: "Resize a volume", - Args: util.Validate, + Args: util.ValidateExact, ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(client.Volume().Names)), TraverseChildren: true, DisableFlagsInUseLine: true, diff --git a/internal/cmd/volume/volume.go b/internal/cmd/volume/volume.go index 911c48985..e6b45ac32 100644 --- a/internal/cmd/volume/volume.go +++ b/internal/cmd/volume/volume.go @@ -11,7 +11,7 @@ func NewCommand(s state.State) *cobra.Command { cmd := &cobra.Command{ Use: "volume", Short: "Manage Volumes", - Args: util.Validate, + Args: util.ValidateExact, TraverseChildren: true, DisableFlagsInUseLine: true, }