piston/cli/commands/ppman_commands/install.js

27 lines
830 B
JavaScript
Raw Normal View History

2021-02-27 07:30:11 +01:00
const {PistonEngine} = require('piston-api-client');
const chalk = require('chalk');
exports.command = ['install <language> <language-version>']
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
}
exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']);
2021-03-06 07:27:13 +01:00
const opts = {
language: argv['language'],
version: argv['language-version']
};
2021-02-27 07:30:11 +01:00
2021-03-06 07:27:13 +01:00
const install = await api.install_package(opts).catch(x=>x);
2021-02-27 07:30:11 +01:00
console.log(msg_format.color(install));
}