Skip to content

Commit

Permalink
Merge pull request #897 from rsteube/env-group
Browse files Browse the repository at this point in the history
env: group as constants
  • Loading branch information
rsteube authored Aug 11, 2023
2 parents 67fe5b4 + 7a64bb3 commit ad4983c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@ import (
"github.com/rsteube/carapace/internal/common"
)

const (
CARAPACE_COVERDIR = "CARAPACE_COVERDIR" // coverage directory for sandbox tests
CARAPACE_HIDDEN = "CARAPACE_HIDDEN" // show hidden commands/flags
CARAPACE_LENIENT = "CARAPACE_LENIENT" // allow unknown flags
CARAPACE_LOG = "CARAPACE_LOG" // enable logging
CARAPACE_MATCH = "CARAPACE_MATCH" // match case insensitive
CARAPACE_SANDBOX = "CARAPACE_SANDBOX" // mock context for sandbox tests
CARAPACE_ZSH_HASH_DIRS = "CARAPACE_ZSH_HASH_DIRS" // zsh hash directories
CLICOLOR = "CLICOLOR" // disable color
NO_COLOR = "NO_COLOR" // disable color
)

func ColorDisabled() bool {
return os.Getenv("NO_COLOR") != "" || os.Getenv("CLICOLOR") == "0"
return os.Getenv(NO_COLOR) != "" || os.Getenv(CLICOLOR) == "0"
}

func Lenient() bool {
return os.Getenv("CARAPACE_LENIENT") != ""
return os.Getenv(CARAPACE_LENIENT) != ""
}

func Hashdirs() string {
return os.Getenv("CARAPACE_ZSH_HASH_DIRS")
return os.Getenv(CARAPACE_ZSH_HASH_DIRS)
}

func Sandbox() (m *common.Mock, err error) {
sandbox := os.Getenv("CARAPACE_SANDBOX")
sandbox := os.Getenv(CARAPACE_SANDBOX)
if sandbox == "" || !isGoRun() {
return nil, errors.New("no sandbox")
}
Expand All @@ -32,19 +44,19 @@ func Sandbox() (m *common.Mock, err error) {
}

func Log() bool {
return os.Getenv("CARAPACE_LOG") != ""
return os.Getenv(CARAPACE_LOG) != ""
}

func Hidden() bool {
return os.Getenv("CARAPACE_HIDDEN") != ""
return os.Getenv(CARAPACE_HIDDEN) != ""
}

func CoverDir() string {
return os.Getenv("CARAPACE_COVERDIR") // custom env for GOCOVERDIR so that it works together with `-coverprofile`
return os.Getenv(CARAPACE_COVERDIR) // custom env for GOCOVERDIR so that it works together with `-coverprofile`
}

func isGoRun() bool { return strings.HasPrefix(os.Args[0], os.TempDir()+"/go-build") }

func Match() string { // see match.Match
return os.Getenv("CASE_INSENSITIVE")
return os.Getenv(CARAPACE_MATCH)
}

0 comments on commit ad4983c

Please sign in to comment.