cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.12k stars 292 forks source link

cmd/cue: add env command #2838

Open myitcv opened 8 months ago

myitcv commented 8 months ago

As we add more environment variables it will be useful to unequivocally know what env is active during a CUE load/evaluation etc.

For example, as part of modules we added the flag CUE_EXPERIMENT=modules. Performance improvements via the evaluator will likely introduce more experiments, but also CUE_DEBUG values.

Go has go env for dumping useful effective environment information:

$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN='/home/myitcv/dev/cuelang/bin'
GOCACHE='/home/myitcv/.cache/go-build'
GOENV='/home/myitcv/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/myitcv/gostuff/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/myitcv/gostuff'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/myitcv/gos'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/myitcv/gos/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/myitcv/dev/cuelang/cuelang.org/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build307901028=/tmp/go-build -gno-record-gcc-switches'

"Effective" in so far as the value of a variable shown is the value after defaults etc have been applied.

We should add cue env in the same spirit, and also make the reporting of the value of cue env part of the GitHub bug report issue template.

mvdan commented 8 months ago

In the future this also enables adding cue env -w, much like go env -w, which I think has been helpful for portable scripting across OSes.

jpluscplusm commented 3 weeks ago

This would be useful when dynamically setting up a CI cache to store the contents of CUE_CACHE_DIR. Currently I either have to set CUE_CACHE_DIR explicitly, in the env (and cache that specific directory), or take a guess at the value that's being used by the command when setting up the CI cache.