Last active
February 21, 2024 19:33
-
-
Save cxmeel/97590dd84e795063646a7b085486006e to your computer and use it in GitHub Desktop.
Pretty-prints the current state of the OS environment to the console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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