Skip to content

Commit 7e0d935

Browse files
authored
Merge pull request #297 from lets-cli/codex/add-letsos-and-letsarch-env
Add normalized LETS_OS and LETS_ARCH environment vars
2 parents cccbc25 + 0e21735 commit 7e0d935

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

docs/docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ title: Changelog
77

88
* `[Added]` Show similar command suggestions on typos.
99
* `[Changed]` Exit code 2 on unknown command.
10+
* `[Added]` Expose `LETS_OS` and `LETS_ARCH` environment variables at command runtime.
1011
* `[Removed]` Drop deprecated `eval_env` directive. Use `env` with `sh` execution mode instead.
1112
* `[Fixed]` Evaluate `env` entries sequentially so `sh` values can reference previously resolved env keys (including global env for command-level env).
1213

docs/docs/env.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ title: Environment
1919
* `LETS_COMMAND_WORK_DIR` - absolute path to `work_dir` specified in command.
2020
* `LETS_CONFIG` - absolute path to lets config file.
2121
* `LETS_CONFIG_DIR` - absolute path to lets config file firectory.
22+
* `LETS_OS` - current operating system name from Go runtime, for example `linux`, `darwin`, `windows`
23+
* `LETS_ARCH` - current architecture name from Go runtime, for example `amd64`, `arm64`, `386`
2224
* `LETS_SHELL` - shell from config or command.
2325
* `LETSOPT_<>` - options parsed from command `options` (docopt string). E.g `lets run --env=prod --reload` will be `LETSOPT_ENV=prod` and `LETSOPT_RELOAD=true`
2426
* `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`

internal/executor/executor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11+
"runtime"
1112
"strings"
1213

1314
"github.com/lets-cli/lets/internal/checksum"
@@ -210,6 +211,8 @@ func (e *Executor) setupEnv(osCmd *exec.Cmd, command *config.Command, shell stri
210211
"LETS_COMMAND_WORK_DIR": osCmd.Dir,
211212
"LETS_CONFIG": filepath.Base(e.cfg.FilePath),
212213
"LETS_CONFIG_DIR": filepath.Dir(e.cfg.FilePath),
214+
"LETS_OS": runtime.GOOS,
215+
"LETS_ARCH": runtime.GOARCH,
213216
"LETS_SHELL": shell,
214217
}
215218

tests/default_env.bats

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ setup() {
6262

6363
assert_failure
6464
assert_line --index 0 "failed to run command 'print-workdir': chdir ${TEST_DIR}/b: no such file or directory"
65-
}
65+
}
66+
67+
@test "LETS_OS and LETS_ARCH: contain Go runtime platform values" {
68+
run lets print-os-arch
69+
70+
assert_success
71+
assert_line --index 0 "LETS_OS=$(go env GOOS)"
72+
assert_line --index 1 "LETS_ARCH=$(go env GOARCH)"
73+
}

tests/default_env/lets.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ commands:
1313
print-env:
1414
options: |
1515
Usage: lets print-env <env>
16-
cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}`
16+
cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}`
17+
18+
print-os-arch:
19+
cmd: |
20+
echo LETS_OS=${LETS_OS}
21+
echo LETS_ARCH=${LETS_ARCH}

0 commit comments

Comments
 (0)