Skip to content

Commit fee54c2

Browse files
fix: prevent filename completion of flags that don't take filename args (#498)
Similar as/continuation of #366, splitting off #491. --------- Co-authored-by: Ville Välimäki <ville.valimaki@upcloud.com>
1 parent 72a7720 commit fee54c2

32 files changed

Lines changed: 74 additions & 14 deletions

internal/commands/database/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/UpCloudLtd/upcloud-cli/v3/internal/ui"
1616
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
1717
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
18+
"github.com/spf13/cobra"
1819
"github.com/spf13/pflag"
1920
)
2021

@@ -199,6 +200,9 @@ func (s *createCommand) InitCommand() {
199200
commands.Must(s.Cobra().MarkFlagRequired("title"))
200201
commands.Must(s.Cobra().MarkFlagRequired("zone"))
201202
commands.Must(s.Cobra().MarkFlagRequired("hostname-prefix"))
203+
for _, flag := range []string{"hostname-prefix", "title", "plan", "maintenance-dow", "maintenance-time", "label", "network", "property"} {
204+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
205+
}
202206
}
203207

204208
func (s *createCommand) InitCommandWithConfig(cfg *config.Config) {

internal/commands/database/session/cancel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
1313
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
14+
"github.com/spf13/cobra"
1415
"github.com/spf13/pflag"
1516
)
1617

@@ -42,7 +43,7 @@ func (s *cancelCommand) InitCommand() {
4243

4344
s.AddFlags(flagSet)
4445
commands.Must(s.Cobra().MarkFlagRequired("pid"))
45-
commands.Must(flagSet.SetAnnotation("pid", commands.FlagAnnotationNoFileCompletions, nil))
46+
commands.Must(s.Cobra().RegisterFlagCompletionFunc("pid", cobra.NoFileCompletions))
4647
}
4748

4849
// Execute implements commands.MultipleArgumentCommand

internal/commands/ipaddress/modify.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
99
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
1010
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
11+
"github.com/spf13/cobra"
1112
"github.com/spf13/pflag"
1213
)
1314

@@ -37,6 +38,9 @@ func (s *modifyCommand) InitCommand() {
3738
fs.StringVar(&s.mac, "mac", "", "MAC address of server interface to attach floating IP to.")
3839
fs.StringVar(&s.ptrrecord, "ptr-record", "", "New fully qualified domain name to set as the PTR record for the IP address.")
3940
s.AddFlags(fs)
41+
for _, flag := range []string{"mac", "ptr-record"} {
42+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
43+
}
4044
}
4145

4246
// MaximumExecutions implements Command.MaximumExecutions

internal/commands/kubernetes/modify.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ func (c *modifyCommand) InitCommand() {
5555

5656
c.AddFlags(fs)
5757
c.Cobra().MarkFlagsMutuallyExclusive("label", "clear-labels")
58-
commands.Must(c.Cobra().RegisterFlagCompletionFunc("label", cobra.NoFileCompletions))
58+
for _, flag := range []string{"kubernetes-api-allow-ip", "label"} {
59+
commands.Must(c.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
60+
}
5961
}
6062

6163
// Execute implements commands.MultipleArgumentCommand

internal/commands/kubernetes/nodegroup/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func GetCreateNodeGroupFlagSet(p *CreateNodeGroupParams) *pflag.FlagSet {
4747
commands.Must(fs.SetAnnotation("kubelet-arg", commands.FlagAnnotationNoFileCompletions, nil))
4848
commands.Must(fs.SetAnnotation("label", commands.FlagAnnotationNoFileCompletions, nil))
4949
commands.Must(fs.SetAnnotation("name", commands.FlagAnnotationNoFileCompletions, nil))
50+
commands.Must(fs.SetAnnotation("ssh-key", commands.FlagAnnotationNoFileCompletions, nil))
5051
commands.Must(fs.SetAnnotation("storage", commands.FlagAnnotationNoFileCompletions, nil))
5152
commands.Must(fs.SetAnnotation("taint", commands.FlagAnnotationNoFileCompletions, nil))
5253

internal/commands/network/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/UpCloudLtd/upcloud-cli/v3/internal/ui"
1313
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
1414
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
15+
"github.com/spf13/cobra"
1516
"github.com/spf13/pflag"
1617
)
1718

@@ -58,6 +59,9 @@ func (s *createCommand) InitCommand() {
5859
commands.Must(s.Cobra().MarkFlagRequired("name"))
5960
commands.Must(s.Cobra().MarkFlagRequired("zone"))
6061
commands.Must(s.Cobra().MarkFlagRequired("ip-network"))
62+
for _, flag := range []string{"name", "ip-network"} {
63+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
64+
}
6165
}
6266

6367
func (s *createCommand) InitCommandWithConfig(cfg *config.Config) {

internal/commands/network/modify.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
77
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
8+
"github.com/spf13/cobra"
89
"github.com/spf13/pflag"
910

1011
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
@@ -53,6 +54,9 @@ func (s *modifyCommand) InitCommand() {
5354
" dhcp-default-route: true/false \n"+
5455
" dhcp-dns: array of strings")
5556
s.AddFlags(fs)
57+
for _, flag := range []string{"name", "ip-network"} {
58+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
59+
}
5660
}
5761

5862
func (s *modifyCommand) InitCommandWithConfig(cfg *config.Config) {

internal/commands/server/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ Note that the default template, Ubuntu Server 24.04 LTS (Noble Numbat), only sup
307307
commands.Must(s.Cobra().RegisterFlagCompletionFunc("password-delivery", cobra.FixedCompletions(passwordDeliveries, cobra.ShellCompDirectiveNoFileComp)))
308308
commands.Must(s.Cobra().RegisterFlagCompletionFunc("remote-access-type", cobra.FixedCompletions(remoteAccessTypes, cobra.ShellCompDirectiveNoFileComp)))
309309
commands.Must(s.Cobra().RegisterFlagCompletionFunc("video-model", cobra.FixedCompletions(videoModels, cobra.ShellCompDirectiveNoFileComp)))
310+
for _, flag := range []string{
311+
"boot-order", "cores", "hostname", "label", "memory", "network", "os", "os-storage-size", "remote-access-password",
312+
"simple-backup", "storage", "title", "user-data", "username",
313+
} {
314+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
315+
}
310316
}
311317

312318
func (s *createCommand) InitCommandWithConfig(cfg *config.Config) {

internal/commands/server/firewall/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ To edit the default rule of the firewall, set only ` + "`" + `--direction` + "`"
8888
commands.Must(s.Cobra().RegisterFlagCompletionFunc("action", cobra.FixedCompletions(actions, cobra.ShellCompDirectiveNoFileComp)))
8989
commands.Must(s.Cobra().RegisterFlagCompletionFunc("family", cobra.FixedCompletions(ipaddress.Families, cobra.ShellCompDirectiveNoFileComp)))
9090
commands.Must(s.Cobra().RegisterFlagCompletionFunc("protocol", cobra.FixedCompletions(protocols, cobra.ShellCompDirectiveNoFileComp)))
91+
for _, flag := range []string{
92+
"position", "icmp-type", "dest-ipaddress-block", "destination-port-start", "destination-port-end",
93+
"src-ipaddress-block", "source-port-start", "source-port-end", "comment",
94+
} {
95+
commands.Must(s.Cobra().RegisterFlagCompletionFunc(flag, cobra.NoFileCompletions))
96+
}
9197
}
9298

9399
// Execute implements commands.MultipleArgumentCommand

internal/commands/server/firewall/delete.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
99
"github.com/UpCloudLtd/upcloud-cli/v3/internal/resolver"
1010
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
11+
"github.com/spf13/cobra"
1112
"github.com/spf13/pflag"
1213
)
1314

@@ -36,6 +37,7 @@ func (s *deleteCommand) InitCommand() {
3637
s.AddFlags(flagSet)
3738

3839
commands.Must(s.Cobra().MarkFlagRequired("position"))
40+
commands.Must(s.Cobra().RegisterFlagCompletionFunc("position", cobra.NoFileCompletions))
3941
}
4042

4143
// Execute implements commands.MultipleArgumentCommand

0 commit comments

Comments
 (0)