piston/cli/commands/ppman_commands/list.js

27 lines
697 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 = ['list']
exports.aliases = ['l']
exports.describe = 'Lists all available packages'
const msg_format = {
'color': p => `${chalk[p.installed ? "green":"red"]("•")} ${p.language} ${p.language_version}`,
'monochrome': p => `${p.language} ${p.language_version} ${p.installed ? "(INSTALLED)": ""}`,
'json': JSON.stringify
}
exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']);
2021-03-05 07:40:47 +01:00
2021-03-06 07:27:13 +01:00
const packages = await api.list_packages();
2021-03-05 07:40:47 +01:00
2021-03-06 07:27:13 +01:00
2021-02-27 07:30:11 +01:00
const pkg_msg = packages
.map(msg_format.color)
.join('\n');
console.log(pkg_msg);
}