piston/cli/commands/ppman_commands/install.js

24 lines
771 B
JavaScript
Raw Normal View History

2021-02-27 07:30:11 +01:00
const chalk = require('chalk');
2021-04-23 01:59:54 +02:00
exports.command = ['install <language> [language-version]']
2021-02-27 07:30:11 +01:00
exports.aliases = ['i']
exports.describe = 'Installs the named package'
const msg_format = {
2021-02-27 13:16:33 +01:00
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
'monochrome': p => `Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
2021-02-27 07:30:11 +01:00
'json': JSON.stringify
}
2021-03-13 04:44:33 +01:00
exports.handler = async function({axios, language, languageVersion}){
try{
2021-04-23 01:59:54 +02:00
const install = await axios.post(`/api/v1/packages/${language}/${languageVersion || '*'}`)
2021-04-23 01:43:21 +02:00
2021-03-13 04:44:33 +01:00
console.log(msg_format.color(install.data));
}catch({response}){
console.error(response.data.message)
}
2021-04-23 01:43:21 +02:00
}