Skip to content

Commit

Permalink
Merge pull request #1855 from rsteube/env-carapace
Browse files Browse the repository at this point in the history
environment: update carapace
  • Loading branch information
rsteube authored Sep 20, 2023
2 parents fa4e40d + dfb601f commit cca5ad9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/actions/env/carapace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(),
},
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/actions/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 {
Expand Down

0 comments on commit cca5ad9

Please sign in to comment.