piston/cli/commands/ppman_commands/uninstall.js

36 lines
1.1 KiB
JavaScript
Raw 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) {
[language, language_version] = package.split("=")
res = {
language: language,
version: language_version || "*"
};
return res
}
2021-04-10 06:10:18 +02:00
const msg_format = {
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-04-23 01:43:21 +02:00
const uninstall = await axios.delete(`/api/v2/packages`, { data: request });
console.log(msg_format.color(uninstall.data));
} catch ({ response }) {
console.error(response.data.message)
}
2021-04-10 06:10:18 +02:00
}
}