1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---@meta
local
--- Creates a new environment that inherits values from the specified base environment.
--- The derived environment maintains a dynamic link to the base environment, so any values set in the base environment
--- after the derivation will still be accessible in the derived environment, unless they are shadowed by values
--- set directly in the derived environment.
--- This allows the derived environment to stay updated with changes to the base environment, while also allowing
--- customizations specific to the derived environment.
---
---@param env Environment|nil The base environment to inherit from. If not provided, defaults to the current environment.
---@return Environment A new `Environment` instance with inherited values from `env`.
--- Temporarily sets the specified environment as the active `context.env` for the duration of a function's execution.
--- This allows a command to run with an isolated environment that will automatically revert once the function completes,
--- even if an error is raised. If `func` raises an error, `Context:with` will properly restore the previous environment
--- before propagating the error.
---
---@param env Environment The environment to set as `context.env` during the function's execution.
---@param func fun():any The function to execute with `env` as the active environment.
---@return any The return value of the function executed in the specified environment.
--- Represents a collection of key-value pairs stored across runs and used to share configuration data between commands.
--- Environments can inherit values from other environments and are passed to sub-commands as needed.
--- Commands may modify their environment and declare sub-commands that utilize these values (e.g., `configure` might set
--- environment variables that the `build` command then uses).
--- Additionally, environments track values that are read during execution to check if a stage is up-to-date on subsequent runs.
---@class Environment
---@field [string] EnvironmentValue A dynamic key-value storage for environment variables.
Environment =
--- A value type that can be stored within an environment. Supported types include `nil`, `boolean`, `string`, `number`,
--- arrays of `EnvironmentValue`, or `Node` references.
---@alias EnvironmentValue nil|boolean|string|number|EnvironmentValue[]|Node