Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (typo): Fix typo in LETS_CONFIG_DIR description ('firectory' -> 'directory').

Suggested change
* `LETS_CONFIG_DIR` - absolute path to lets config file firectory.
* `LETS_CONFIG_DIR` - absolute path to lets config file directory.

* `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`
Expand Down
3 changes: 3 additions & 0 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/lets-cli/lets/internal/checksum"
Expand Down Expand Up @@ -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,
}

Expand Down
10 changes: 9 additions & 1 deletion tests/default_env.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

@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)"
}
7 changes: 6 additions & 1 deletion tests/default_env/lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ commands:
print-env:
options: |
Usage: lets print-env <env>
cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}`
cmd: echo ${LETSOPT_ENV}=`printenv ${LETSOPT_ENV}`

print-os-arch:
cmd: |
echo LETS_OS=${LETS_OS}
echo LETS_ARCH=${LETS_ARCH}
Loading