Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env: group as constants #897

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}