Skip to content

Commit ce1aebc

Browse files
committed
cli/command/completion: add Platforms
Add a utility for completing platform strings. Platforms offers completion for platform-strings. It provides a non-exhaustive list of platforms to be used for completion. Platform-strings are based on [runtime.GOOS] and [runtime.GOARCH], but with (optional) variants added. A list of recognised os/arch combinations from the Go runtime can be obtained through "go tool dist list". Some noteworthy exclusions from this list: - arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows. - we don't (yet) include `os-variant` for completion (as can be used for Windows images) - we don't (yet) include platforms for which we don't build binaries, such as BSD platforms (freebsd, netbsd, openbsd), android, macOS (darwin). - 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. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 55ae7d7 commit ce1aebc

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

cli/command/completion/functions.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,47 @@ func FileNames(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCom
145145
func NoComplete(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
146146
return nil, cobra.ShellCompDirectiveNoFileComp
147147
}
148+
149+
var commonPlatforms = []string{
150+
"linux",
151+
"linux/386",
152+
"linux/amd64",
153+
"linux/arm",
154+
"linux/arm/v5",
155+
"linux/arm/v6",
156+
"linux/arm/v7",
157+
"linux/arm64",
158+
"linux/arm64/v8",
159+
160+
// IBM power and z platforms
161+
"linux/ppc64le",
162+
"linux/s390x",
163+
164+
// Not yet supported
165+
"linux/riscv64",
166+
167+
"windows",
168+
"windows/amd64",
169+
170+
"wasip1",
171+
"wasip1/wasm",
172+
}
173+
174+
// Platforms offers completion for platform-strings. It provides a non-exhaustive
175+
// list of platforms to be used for completion. Platform-strings are based on
176+
// [runtime.GOOS] and [runtime.GOARCH], but with (optional) variants added. A
177+
// list of recognised os/arch combinations from the Go runtime can be obtained
178+
// through "go tool dist list".
179+
//
180+
// Some noteworthy exclusions from this list:
181+
//
182+
// - arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows.
183+
// - we don't (yet) include `os-variant` for completion (as can be used for Windows images)
184+
// - we don't (yet) include platforms for which we don't build binaries, such as
185+
// BSD platforms (freebsd, netbsd, openbsd), android, macOS (darwin).
186+
// - we currently exclude architectures that may have unofficial builds,
187+
// but don't have wide adoption (and no support), such as loong64, mipsXXX,
188+
// ppc64 (non-le) to prevent confusion.
189+
func Platforms(_ *cobra.Command, _ []string, _ string) (platforms []string, _ cobra.ShellCompDirective) {
190+
return commonPlatforms, cobra.ShellCompDirectiveNoFileComp
191+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package completion
2+
3+
import (
4+
"testing"
5+
6+
"github.com/spf13/cobra"
7+
"gotest.tools/v3/assert"
8+
is "gotest.tools/v3/assert/cmp"
9+
)
10+
11+
func TestCompletePlatforms(t *testing.T) {
12+
values, directives := Platforms(nil, nil, "")
13+
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")
14+
assert.Check(t, is.DeepEqual(values, commonPlatforms))
15+
}

0 commit comments

Comments
 (0)