mirror of
https://github.com/matrix-construct/construct
synced 2024-06-12 15:08:55 +02:00
modules/console: Add cmd to explore posix env vars.
This commit is contained in:
parent
e6a62b41b3
commit
5b9a6efc54
|
@ -554,6 +554,53 @@ console_cmd__mem(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// env
|
||||
//
|
||||
|
||||
bool
|
||||
console_cmd__env(opt &out, const string_view &line)
|
||||
{
|
||||
if(!::environ)
|
||||
throw error
|
||||
{
|
||||
"Env variable list not available."
|
||||
};
|
||||
|
||||
const params param{line, " ",
|
||||
{
|
||||
"key"
|
||||
}};
|
||||
|
||||
if(param["key"] == "*")
|
||||
{
|
||||
for(const char *const *e(::environ); *e; ++e)
|
||||
out << *e << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(param["key"])
|
||||
{
|
||||
out << util::getenv(param["key"]) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
for(const char *const *e(::environ); *e; ++e)
|
||||
{
|
||||
string_view kv[2];
|
||||
tokens(*e, '=', kv);
|
||||
if(!startswith(kv[0], "IRCD_") && !startswith(kv[0], "ircd_"))
|
||||
continue;
|
||||
|
||||
out << std::setw(64) << std::left << kv[0]
|
||||
<< " :" << kv[1]
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// conf
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue