@@ -5,27 +5,8 @@
['render:format'] = 'html';
['html:gen-styles'] = true;
}
-local function
-kmap(fn, list)
- local new = {}
- for k, v in pairs(list) do
- local nk,nv = fn(k,v)
- new[nk or k] = nv or v
- end
- return new
-end
-
-local function
-kfilter(list, fn)
- local new = {}
- for k, v in pairs(list) do
- if fn(k,v) then new[k] = v end
- end
- return new
-end
-
local function
main(input, output, log, mode, suggestions, vars)
local doc = ct.parse(input.stream, input.src, mode)
input.stream:close()
@@ -46,11 +27,11 @@
if not ct.render[mode['render:format']] then
ct.exns.unimpl('output format ā%sā unsupported', mode['render:format']):throw()
end
- local render_opts = kmap(function(k,v)
+ local render_opts = ss.kmap(function(k,v)
return k:sub(2+#mode['render:format'])
- end, kfilter(mode, function(m)
+ end, ss.kfilter(mode, function(m)
return ss.str.begins(m, mode['render:format']..':')
end))
doc.vars = vars
@@ -139,8 +120,31 @@
['mode-weak'] = function(key,value) suggestions[checkmodekey(key)] = value end;
['mode-set-weak'] = function(key) suggestions[checkmodekey(key)] = true end;
['mode-clear-weak'] = function(key) suggestions[checkmodekey(key)] = false end;
+
+ ['version'] = function()
+ outp:write(ct.info:about())
+ if next(ct.ext.loaded) then
+ outp:write('\nactive extensions:\n')
+ for k,v in pairs(ct.ext.loaded) do
+ outp:write(string.format(' * %s', v.id ..
+ (v.version and (' ' .. v.version:string()) or '')))
+ if v.desc then
+ outp:write(string.format(': %s', v.desc))
+ if v.contributors then
+ outp:write(string.format(' [%s]', table.concat(
+ ss.map(function(ctr)
+ return ctr.name or ctr.handle
+ end, v.contributors), ', ')))
+ end
+ else
+ outp:write'\n'
+ end
+ end
+ end
+ os.exit(0)
+ end
}
local args = {}
local keepParsing = true
@@ -152,17 +156,19 @@
local nargs = optnparams(longopt)
if nargs > 1 then
if i + nargs > #arg then
- ct.exns.cli('not enough arguments for switch --%s (%u expected)', longopt, nargs):throw()
+ ct.exns.cli('not enough arguments for switch --%s (%s expected)', longopt, nargs):throw()
end
local nt = {}
for j = i+1, i+nargs do
table.insert(nt, arg[j])
end
- onswitch[longopt](table.unpack(nt))
+ print('onsw')
elseif nargs == 1 then
onswitch[longopt](arg[i+1])
+ else
+ onswitch[longopt]()
end
i = i + nargs
end
if v == '--' then
@@ -176,9 +182,9 @@
for c,p in ss.str.enc.utf8.each(v:sub(2)) do
if optmap[c] then
execLongOpt(optmap[c])
else
- ct.exns.cli('switch -%i unrecognized', c):throw()
+ ct.exns.cli('switch -%s unrecognized', c):throw()
end
end
else
table.insert(args, v)