Comparison

plugins/mod_admin_shell.lua @ 11364:bb6b744f7f1a

mod_admin_shell: Pretty-print HTTP endpoints in a human table Attempted readability improvement
author Kim Alvefur <zash@zash.se>
date Wed, 03 Feb 2021 23:46:13 +0100
parent 11363:8cbe951b40e3
child 11365:5eb817cdd5cd
comparison
equal deleted inserted replaced
11363:8cbe951b40e3 11364:bb6b744f7f1a
35 local serialization = require "util.serialization"; 35 local serialization = require "util.serialization";
36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); 36 local serialize_config = serialization.new ({ fatal = false, unquoted = true});
37 local time = require "util.time"; 37 local time = require "util.time";
38 38
39 local format_number = require "util.human.units".format; 39 local format_number = require "util.human.units".format;
40 local format_table = require "util.human.io".table;
40 41
41 local commands = module:shared("commands") 42 local commands = module:shared("commands")
42 local def_env = module:shared("env"); 43 local def_env = module:shared("env");
43 local default_env_mt = { __index = def_env }; 44 local default_env_mt = { __index = def_env };
44 45
1223 def_env.http = {}; 1224 def_env.http = {};
1224 1225
1225 function def_env.http:list(hosts) 1226 function def_env.http:list(hosts)
1226 local print = self.session.print; 1227 local print = self.session.print;
1227 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts); 1228 hosts = array.collect(set.new({ not hosts and "*" or nil }) + get_hosts_set(hosts)):sort(_sort_hosts);
1229 local output = format_table({
1230 { title = "Module", width = "20%" },
1231 { title = "URL", width = "80%" },
1232 }, 132);
1228 1233
1229 for _, host in ipairs(hosts) do 1234 for _, host in ipairs(hosts) do
1230 local http_apps = modulemanager.get_items("http-provider", host); 1235 local http_apps = modulemanager.get_items("http-provider", host);
1231 if #http_apps > 0 then 1236 if #http_apps > 0 then
1232 local http_host = module:context(host):get_option_string("http_host"); 1237 local http_host = module:context(host):get_option_string("http_host");
1233 if host == "*" then 1238 if host == "*" then
1234 print("Global HTTP endpoints available on all hosts:"); 1239 print("Global HTTP endpoints available on all hosts:");
1235 else 1240 else
1236 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":")); 1241 print("HTTP endpoints on "..host..(http_host and (" (using "..http_host.."):") or ":"));
1237 end 1242 end
1243 print(output());
1238 for _, provider in ipairs(http_apps) do 1244 for _, provider in ipairs(http_apps) do
1239 local mod = provider._provided_by; 1245 local mod = provider._provided_by;
1240 local url = module:context(host):http_url(provider.name, provider.default_path); 1246 local url = module:context(host):http_url(provider.name, provider.default_path);
1241 mod = mod and "mod_"..mod or "" 1247 mod = mod and "mod_"..mod or ""
1242 print("", mod, url); 1248 print(output{mod, url});
1243 end 1249 end
1244 print(""); 1250 print("");
1245 end 1251 end
1246 end 1252 end
1247 1253