-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add process label (resty-cli v0.30) (#12)
- Loading branch information
Showing
8 changed files
with
159 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
local fname = os.getenv("RUSTY_CLI_TEST_OUTPUT") or "/dev/stdout" | ||
local fh = assert(io.open(fname, "w+")) | ||
|
||
local keys = {} | ||
local PROC_SELF = "/proc/" .. ngx.worker.pid() | ||
|
||
for k in pairs(arg) do | ||
table.insert(keys, k) | ||
local function exec(cmd) | ||
local proc = io.popen(cmd, "r") | ||
local out = proc:read("*a") | ||
proc:close() | ||
|
||
out = out:gsub("\n$", "") | ||
return out | ||
end | ||
|
||
table.sort(keys) | ||
local function get_cmd() | ||
local proc = io.open(PROC_SELF .. "/cmdline", "r") | ||
local data = proc:read("*a") | ||
proc:close() | ||
|
||
local items = {} | ||
|
||
data:gsub("[^%z]+", function(item) | ||
table.insert(items, item) | ||
end) | ||
|
||
return items | ||
end | ||
|
||
local function printf(...) | ||
return fh:write(string.format(...)) | ||
end | ||
|
||
|
||
printf("CWD = %q\n", exec("readlink " .. PROC_SELF .. "/cwd")) | ||
printf("EXE = %q\n", exec("readlink " .. PROC_SELF .. "/exe")) | ||
|
||
do | ||
printf("CMD = {\n") | ||
for i, elem in ipairs(get_cmd()) do | ||
printf(" [%s] = %q\n", i, elem) | ||
end | ||
printf("}\n") | ||
end | ||
|
||
do | ||
local keys = {} | ||
|
||
for k in pairs(arg) do | ||
table.insert(keys, k) | ||
end | ||
|
||
for _, k in ipairs(keys) do | ||
local key = ("arg[%s]"):format(k) | ||
table.sort(keys) | ||
|
||
fh:write(("%-10s = %q\n"):format(key, arg[k])) | ||
printf("ARG = {\n") | ||
for _, k in ipairs(keys) do | ||
printf(" [%s] = %q\n", k, arg[k]) | ||
end | ||
printf("}\n") | ||
end | ||
|
||
fh:close() |
This file contains 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
This file contains 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