piston/cli/commands/ppman_commands/list.js

26 lines
655 B
JavaScript

//const fetch = require('node-fetch');
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({axios}){
const packages = await axios.get('/packages');
const pkg_msg = packages.data.data.packages
.map(msg_format.color)
.join('\n');
console.log(pkg_msg);
}