From 810be9fbe920891936f67fcfd31bf4fa72331330 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 30 Aug 2025 11:26:54 +0200 Subject: [PATCH] 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 --- cli/command/completion/functions.go | 6 ++++-- cli/command/completion/functions_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/command/completion/functions.go b/cli/command/completion/functions.go index 2272a53ab..c2faaa2b6 100644 --- a/cli/command/completion/functions.go +++ b/cli/command/completion/functions.go @@ -177,6 +177,8 @@ var commonPlatforms = []string{ // - we currently exclude architectures that may have unofficial builds, // but don't have wide adoption (and no support), such as loong64, mipsXXX, // ppc64 (non-le) to prevent confusion. -func Platforms(_ *cobra.Command, _ []string, _ string) (platforms []string, _ cobra.ShellCompDirective) { - return commonPlatforms, cobra.ShellCompDirectiveNoFileComp +func Platforms() cobra.CompletionFunc { + return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return commonPlatforms, cobra.ShellCompDirectiveNoFileComp + } } diff --git a/cli/command/completion/functions_test.go b/cli/command/completion/functions_test.go index 719037467..eef1755ad 100644 --- a/cli/command/completion/functions_test.go +++ b/cli/command/completion/functions_test.go @@ -304,7 +304,7 @@ func TestCompleteNetworkNames(t *testing.T) { } func TestCompletePlatforms(t *testing.T) { - values, directives := Platforms(nil, nil, "") + values, directives := Platforms()(nil, nil, "") assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion") assert.Check(t, is.DeepEqual(values, commonPlatforms)) }