57 lines
1.0 KiB
Lua
57 lines
1.0 KiB
Lua
require "util.printing";
|
|
|
|
local actions = {
|
|
help = require "cli.help",
|
|
query = require "cli.query",
|
|
dump = require "cli.dump",
|
|
pack = require "cli.pack",
|
|
};
|
|
|
|
local function parse_args(...)
|
|
local options = {};
|
|
local args = {};
|
|
|
|
require "util.args" ({
|
|
function (arg)
|
|
if options.action then
|
|
args[#args + 1] = arg;
|
|
else
|
|
options.action = arg;
|
|
end
|
|
|
|
return true, true;
|
|
end,
|
|
repo = function (arg)
|
|
if options.repo ~= nil then
|
|
error "a repo may be specified only once";
|
|
else
|
|
options.repo = arg;
|
|
return true;
|
|
end
|
|
end,
|
|
help = actions.help,
|
|
}, ...);
|
|
|
|
if not options.action then
|
|
error "no action specified";
|
|
end
|
|
|
|
return options, args;
|
|
end
|
|
|
|
return function (...)
|
|
xpcall(
|
|
function (...)
|
|
local options, args = parse_args(...);
|
|
options.repo = options.repo or "https://dl.flathub.org/repo";
|
|
|
|
return actions[options.action](options, table.unpack(args));
|
|
end,
|
|
function (err)
|
|
print(table.concat { "unhandled error: ", err, "\n", debug.traceback(nil, 2):match "^[^\n]+\n(.+)$" });
|
|
end,
|
|
...
|
|
);
|
|
end
|
|
|