Skip to content

Commit 810be9f

Browse files
committed
cli/command/completion: change Platforms to return a cobra.CompletionFunc
It's adding a slight indirection by constructing a function when called, but makes the completion functions more consistent, the signature easier to read, and making the return type a [cobra.CompletionFunc] makes it more transparent what it's intended for, and helps discovery of functions that provide completion. [cobra.CompletionFunc]: https://pkg.go.dev/github.com/spf13/cobra#CompletionFunc Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent d18af47 commit 810be9f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cli/command/completion/functions.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ var commonPlatforms = []string{
177177
// - we currently exclude architectures that may have unofficial builds,
178178
// but don't have wide adoption (and no support), such as loong64, mipsXXX,
179179
// ppc64 (non-le) to prevent confusion.
180-
func Platforms(_ *cobra.Command, _ []string, _ string) (platforms []string, _ cobra.ShellCompDirective) {
181-
return commonPlatforms, cobra.ShellCompDirectiveNoFileComp
180+
func Platforms() cobra.CompletionFunc {
181+
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
182+
return commonPlatforms, cobra.ShellCompDirectiveNoFileComp
183+
}
182184
}

cli/command/completion/functions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestCompleteNetworkNames(t *testing.T) {
304304
}
305305

306306
func TestCompletePlatforms(t *testing.T) {
307-
values, directives := Platforms(nil, nil, "")
307+
values, directives := Platforms()(nil, nil, "")
308308
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")
309309
assert.Check(t, is.DeepEqual(values, commonPlatforms))
310310
}

0 commit comments

Comments
 (0)