170 lines
4.1 KiB
Lua
170 lines
4.1 KiB
Lua
local _VERSION = '0.1.0';
|
|
|
|
local createCcpm = require('/apis/libccpm');
|
|
|
|
local args = table.pack(...);
|
|
local command = args[1];
|
|
|
|
local function printUsage()
|
|
print('ccpm usage:');
|
|
print();
|
|
print('\t\tccpm install <package>');
|
|
print('\t\tccpm reinstall <package>');
|
|
print('\t\tccpm uninstall <package>');
|
|
print('\t\tccpm ls');
|
|
print('\t\tccpm search [term]');
|
|
print('\t\tccpm info <package>');
|
|
print('\t\tccpm registry ls');
|
|
print('\t\tccpm registry add <name> [--branch <b>] [--type github|http]');
|
|
print('\t\tccpm registry rm <name>');
|
|
print('\t\tccpm version');
|
|
print('\t\tccpm help');
|
|
end
|
|
|
|
if command == 'version' or command == '-version' or command == '--version' then
|
|
print('ccpm v' .. _VERSION);
|
|
return;
|
|
end
|
|
|
|
if command == nil or command == '' or command == 'help' or command == '-help' or command == '--help' then
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
local ccpm = createCcpm();
|
|
|
|
local function logLine(msg)
|
|
print(msg);
|
|
end
|
|
|
|
if command == 'install' or command == 'reinstall' then
|
|
local pkg = args[2];
|
|
if not pkg then printUsage(); return; end
|
|
local ok, result = ccpm.install(pkg, { force = command == 'reinstall', log = logLine });
|
|
if not ok then
|
|
print(result);
|
|
return;
|
|
end
|
|
print('=> ' .. pkg .. ' installed.');
|
|
return;
|
|
end
|
|
|
|
if command == 'uninstall' or command == 'remove' or command == 'rm' then
|
|
local pkg = args[2];
|
|
if not pkg then printUsage(); return; end
|
|
local ok, err = ccpm.uninstall(pkg, { log = logLine });
|
|
if not ok then
|
|
print(err);
|
|
return;
|
|
end
|
|
print('=> ' .. pkg .. ' uninstalled.');
|
|
return;
|
|
end
|
|
|
|
if command == 'ls' or command == 'list' then
|
|
local packages = ccpm.list();
|
|
local names = {};
|
|
for name in pairs(packages) do names[#names + 1] = name; end
|
|
table.sort(names);
|
|
if #names == 0 then
|
|
print('No packages installed.');
|
|
return;
|
|
end
|
|
for _, name in ipairs(names) do
|
|
print(name .. ' v' .. tostring(packages[name].version or '?'));
|
|
end
|
|
return;
|
|
end
|
|
|
|
if command == 'search' then
|
|
local results = ccpm.search(args[2]);
|
|
if #results == 0 then
|
|
print('No packages found.');
|
|
return;
|
|
end
|
|
for _, r in ipairs(results) do
|
|
print(r.name .. ' v' .. tostring(r.version) .. ' (' .. r.registry .. ')');
|
|
end
|
|
return;
|
|
end
|
|
|
|
if command == 'info' then
|
|
local pkg = args[2];
|
|
if not pkg then printUsage(); return; end
|
|
local desc = ccpm.info(pkg);
|
|
if not desc then
|
|
print('package not found: ' .. pkg);
|
|
return;
|
|
end
|
|
print(desc.name .. ' v' .. tostring(desc.version or '?'));
|
|
if desc.description then print(desc.description); end
|
|
if desc.dependencies and #desc.dependencies > 0 then
|
|
print('dependencies: ' .. table.concat(desc.dependencies, ', '));
|
|
end
|
|
print('files:');
|
|
for _, f in ipairs(desc.files or {}) do print(' ' .. f); end
|
|
return;
|
|
end
|
|
|
|
if command == 'registry' then
|
|
local sub = args[2];
|
|
|
|
if sub == nil or sub == 'ls' or sub == 'list' then
|
|
local registries = ccpm.listRegistries();
|
|
if #registries == 0 then
|
|
print('No registries configured.');
|
|
return;
|
|
end
|
|
for _, r in ipairs(registries) do
|
|
if r.type == 'github' then
|
|
print(r.name .. ' (github:' .. tostring(r.branch or 'master') .. ')');
|
|
else
|
|
print(r.name .. ' (' .. tostring(r.type or 'http') .. ')');
|
|
end
|
|
end
|
|
return;
|
|
end
|
|
|
|
if sub == 'add' then
|
|
local name = args[3];
|
|
if not name then printUsage(); return; end
|
|
local branch, rtype;
|
|
local i = 4;
|
|
while i <= args.n do
|
|
local a = args[i];
|
|
if a == '--branch' then
|
|
branch = args[i + 1];
|
|
i = i + 1;
|
|
elseif a == '--type' then
|
|
rtype = args[i + 1];
|
|
i = i + 1;
|
|
end
|
|
i = i + 1;
|
|
end
|
|
local ok, err = ccpm.addRegistry(name, { branch = branch, type = rtype });
|
|
if not ok then
|
|
print(err);
|
|
return;
|
|
end
|
|
print('=> registry added: ' .. name);
|
|
return;
|
|
end
|
|
|
|
if sub == 'rm' or sub == 'remove' then
|
|
local name = args[3];
|
|
if not name then printUsage(); return; end
|
|
local ok, err = ccpm.removeRegistry(name);
|
|
if not ok then
|
|
print(err);
|
|
return;
|
|
end
|
|
print('=> registry removed: ' .. name);
|
|
return;
|
|
end
|
|
|
|
printUsage();
|
|
return;
|
|
end
|
|
|
|
printUsage();
|