piston/cli/commands/ppman_commands/uninstall.js

42 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2021-04-10 06:10:18 +02:00
const chalk = require('chalk');
exports.command = ['uninstall <packages...>'];
exports.aliases = ['u'];
exports.describe = 'Uninstalls the named package';
2021-04-10 06:10:18 +02:00
//Splits the package into it's language and version
function split_package(package) {
2021-10-08 15:16:57 +02:00
[language, language_version] = package.split('=');
res = {
language: language,
2021-10-08 15:16:57 +02:00
version: language_version || '*',
};
2021-10-08 15:16:57 +02:00
return res;
}
2021-04-10 06:10:18 +02:00
const msg_format = {
2021-10-08 15:16:57 +02:00
color: p =>
`${
p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')
} Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
monochrome: p =>
`Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
json: JSON.stringify,
};
2021-04-10 06:10:18 +02:00
exports.handler = async ({ axios, packages }) => {
const requests = packages.map(package => split_package(package));
for (request of requests) {
try {
2021-10-08 15:16:57 +02:00
const uninstall = await axios.delete(`/api/v2/packages`, {
data: request,
});
console.log(msg_format.color(uninstall.data));
} catch ({ response }) {
2021-10-08 15:16:57 +02:00
console.error(response.data.message);
}
2021-04-10 06:10:18 +02:00
}
2021-10-08 15:16:57 +02:00
};