From 0e21735a814f9f2e1c9d63113014f9e802e2ea7d Mon Sep 17 00:00:00 2001 From: "m.kindritskiy" Date: Sat, 14 Mar 2026 18:18:06 +0200 Subject: [PATCH] Add LETS_OS and LETS_ARCH env --- docs/docs/changelog.md | 1 + docs/docs/env.md | 2 ++ internal/executor/executor.go | 3 +++ tests/default_env.bats | 10 +++++++++- tests/default_env/lets.yaml | 7 ++++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index d7509db5..30c2f7c5 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -7,6 +7,7 @@ title: Changelog * `[Added]` Show similar command suggestions on typos. * `[Changed]` Exit code 2 on unknown command. +* `[Added]` Expose `LETS_OS` and `LETS_ARCH` environment variables at command runtime. * `[Removed]` Drop deprecated `eval_env` directive. Use `env` with `sh` execution mode instead. ## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59) diff --git a/docs/docs/env.md b/docs/docs/env.md index af9c06e1..94ac973b 100644 --- a/docs/docs/env.md +++ b/docs/docs/env.md @@ -19,6 +19,8 @@ title: Environment * `LETS_COMMAND_WORK_DIR` - absolute path to `work_dir` specified in command. * `LETS_CONFIG` - absolute path to lets config file. * `LETS_CONFIG_DIR` - absolute path to lets config file firectory. +* `LETS_OS` - current operating system name from Go runtime, for example `linux`, `darwin`, `windows` +* `LETS_ARCH` - current architecture name from Go runtime, for example `amd64`, `arm64`, `386` * `LETS_SHELL` - shell from config or command. * `LETSOPT_<>` - options parsed from command `options` (docopt string). E.g `lets run --env=prod --reload` will be `LETSOPT_ENV=prod` and `LETSOPT_RELOAD=true` * `LETSCLI_<>` - options which values is a options usage. E.g `lets run --env=prod --reload` will be `LETSCLI_ENV=--env=prod` and `LETSCLI_RELOAD=--reload` diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 277f5fe7..9823fc33 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "github.com/lets-cli/lets/internal/checksum" @@ -210,6 +211,8 @@ func (e *Executor) setupEnv(osCmd *exec.Cmd, command *config.Command, shell stri "LETS_COMMAND_WORK_DIR": osCmd.Dir, "LETS_CONFIG": filepath.Base(e.cfg.FilePath), "LETS_CONFIG_DIR": filepath.Dir(e.cfg.FilePath), + "LETS_OS": runtime.GOOS, + "LETS_ARCH": runtime.GOARCH, "LETS_SHELL": shell, } diff --git a/tests/default_env.bats b/tests/default_env.bats index b257e636..f2497f91 100644 --- a/tests/default_env.bats +++ b/tests/default_env.bats @@ -62,4 +62,12 @@ setup() { assert_failure assert_line --index 0 "failed to run command 'print-workdir': chdir ${TEST_DIR}/b: no such file or directory" -} \ No newline at end of file +} + +@test "LETS_OS and LETS_ARCH: contain Go runtime platform values" { + run lets print-os-arch + + assert_success + assert_line --index 0 "LETS_OS=$(go env GOOS)" + assert_line --index 1 "LETS_ARCH=$(go env GOARCH)" +} diff --git a/tests/default_env/lets.yaml b/tests/default_env/lets.yaml index 849814b0..39592f04 100644 --- a/tests/default_env/lets.yaml +++ b/tests/default_env/lets.yaml @@ -13,4 +13,9 @@ commands: print-env: options: | Usage: lets print-env - cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}` \ No newline at end of file + cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}` + + print-os-arch: + cmd: | + echo LETS_OS=${LETS_OS} + echo LETS_ARCH=${LETS_ARCH}