From dfb601fb6ba8b5e9ab41efaeec932390b88dd343 Mon Sep 17 00:00:00 2001 From: rsteube Date: Wed, 20 Sep 2023 23:42:35 +0200 Subject: [PATCH] environment: update carapace --- pkg/actions/env/carapace.go | 18 ++++++++++++------ pkg/actions/env/env.go | 5 +++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/actions/env/carapace.go b/pkg/actions/env/carapace.go index 8c0398979f..25a64b33e5 100644 --- a/pkg/actions/env/carapace.go +++ b/pkg/actions/env/carapace.go @@ -2,13 +2,15 @@ package env import ( "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/style" ) func init() { + _bool := carapace.ActionValuesDescribed("0", "disabled", "1", "enabled").StyleF(style.ForKeyword) knownVariables["carapace"] = variables{ Names: map[string]string{ "CARAPACE_COVERDIR": "coverage directory for sandbox tests", - "CARAPACE_ENV": "whether to register get-env, set-env and unset-env", + "CARAPACE_ENV": "register get-env, set-env and unset-env", "CARAPACE_HIDDEN": "show hidden commands/flags", "CARAPACE_LENIENT": "allow unknown flags", "CARAPACE_LOG": "enable logging", @@ -18,11 +20,15 @@ func init() { }, Completion: map[string]carapace.Action{ "CARAPACE_COVERDIR": carapace.ActionDirectories(), - "CARAPACE_ENV": carapace.ActionValues("0", "1"), - "CARAPACE_HIDDEN": carapace.ActionValues("0", "1"), - "CARAPACE_LENIENT": carapace.ActionValues("0", "1"), - "CARAPACE_LOG": carapace.ActionValues("0", "1"), - "CARAPACE_MATCH": carapace.ActionValues("0", "1"), + "CARAPACE_ENV": _bool, + "CARAPACE_HIDDEN": _bool, + "CARAPACE_LENIENT": _bool, + "CARAPACE_LOG": _bool, + "CARAPACE_MATCH": carapace.ActionValuesDescribed( + "0", "CASE_SENSITIVE", + "1", "CASE_INSENSITIVE", + ).StyleF(style.ForKeyword), + "CARAPACE_SANDBOX": carapace.ActionValues(), }, } diff --git a/pkg/actions/env/env.go b/pkg/actions/env/env.go index 21b62b2fd9..08549270a5 100644 --- a/pkg/actions/env/env.go +++ b/pkg/actions/env/env.go @@ -42,6 +42,10 @@ func checkPath(s string) func(c carapace.Context) bool { var knownVariables = map[string]variables{} +// ActionKnownEnvironmentVariables completes known environment variables +// +// GOARCH (The architecture, or processor, for which to compile code) +// GOOS (The operating system for which to compile code) func ActionKnownEnvironmentVariables() carapace.Action { return carapace.Batch( actionKnownEnvironmentVariables(), @@ -65,6 +69,7 @@ func actionKnownEnvironmentVariables() carapace.Action { }).Tag("known environment variables") } +// ActionEnvironmentVariableValues completes values for given environment variable func ActionEnvironmentVariableValues(s string) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { if custom, err := loadCustomVariables(); err == nil {