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>
2024-10-08 07:09:50 -04:00
|
|
|
package completion
|
|
|
|
|
|
|
|
import (
|
2024-10-13 11:48:49 -04:00
|
|
|
"sort"
|
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>
2024-10-08 07:09:50 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2024-10-13 11:48:49 -04:00
|
|
|
"gotest.tools/v3/env"
|
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>
2024-10-08 07:09:50 -04:00
|
|
|
)
|
|
|
|
|
2024-10-13 11:48:49 -04:00
|
|
|
func TestCompleteEnvVarNames(t *testing.T) {
|
|
|
|
env.PatchAll(t, map[string]string{
|
|
|
|
"ENV_A": "hello-a",
|
|
|
|
"ENV_B": "hello-b",
|
|
|
|
})
|
|
|
|
values, directives := EnvVarNames(nil, nil, "")
|
|
|
|
assert.Check(t, is.Equal(directives&cobra.ShellCompDirectiveNoFileComp, cobra.ShellCompDirectiveNoFileComp), "Should not perform file completion")
|
|
|
|
|
|
|
|
sort.Strings(values)
|
|
|
|
expected := []string{"ENV_A", "ENV_B"}
|
|
|
|
assert.Check(t, is.DeepEqual(values, expected))
|
|
|
|
}
|
|
|
|
|
2024-10-13 11:52:50 -04:00
|
|
|
func TestCompleteFileNames(t *testing.T) {
|
|
|
|
values, directives := FileNames(nil, nil, "")
|
|
|
|
assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveDefault))
|
|
|
|
assert.Check(t, is.Len(values, 0))
|
|
|
|
}
|
|
|
|
|
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>
2024-10-08 07:09:50 -04:00
|
|
|
func TestCompletePlatforms(t *testing.T) {
|
|
|
|
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))
|
|
|
|
}
|