Skip to content

Instantly share code, notes, and snippets.

@cxmeel
Last active February 21, 2024 19:33
Show Gist options
  • Save cxmeel/97590dd84e795063646a7b085486006e to your computer and use it in GitHub Desktop.
Save cxmeel/97590dd84e795063646a7b085486006e to your computer and use it in GitHub Desktop.
Pretty-prints the current state of the OS environment to the console
local process = require("@lune/process")
local serde = require("@lune/serde")
local AVAILABLE_FORMATS = {
json = "json",
table = "json",
yml = "yaml",
yaml = "yaml",
toml = "toml",
}
local format = "json"
do
local formatArgPos = table.find(process.args, "--format")
if formatArgPos and process.args[formatArgPos + 1] then
local useFormat = process.args[formatArgPos + 1]
assert(AVAILABLE_FORMATS[useFormat], `Invalid format: "{useFormat}"`)
format = AVAILABLE_FORMATS[useFormat]
end
end
local function main()
local env = {}
for key, value in process.env do
env[key] = value :: any
end
local encoded = serde.encode(format, env, true)
print(encoded)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment