0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-03 17:28:18 +02:00

modules/console: Add argument to list single peer; left justify hostname.

This commit is contained in:
Jason Volk 2018-05-31 10:47:06 -07:00
parent ae3eede730
commit 289f9faf4a

View file

@ -2013,25 +2013,15 @@ console_cmd__peer(opt &out, const string_view &line)
if(out.html)
return html__peer(out, line);
const bool all
{
has(line, "all")
};
for(const auto &p : server::peers)
const auto print{[&out]
(const auto &host, const auto &peer)
{
using std::setw;
using std::left;
using std::right;
const auto &host{p.first};
const auto &peer{*p.second};
const net::ipport &ipp{peer.remote};
if(peer.err_has() && !all)
continue;
out << setw(40) << right << host;
out << setw(40) << left << host;
if(ipp)
out << ' ' << setw(22) << left << ipp;
@ -2053,6 +2043,42 @@ console_cmd__peer(opt &out, const string_view &line)
out << " <unknown error>"_sv;
out << std::endl;
}};
const params param{line, " ",
{
"[hostport]", "[all]"
}};
const auto &hostport
{
param[0]
};
const bool all
{
has(line, "all")
};
if(hostport && hostport != "all")
{
auto &peer
{
server::find(hostport)
};
print(peer.hostname, peer);
return true;
}
for(const auto &p : server::peers)
{
const auto &host{p.first};
const auto &peer{*p.second};
if(peer.err_has() && !all)
continue;
print(host, peer);
}
return true;