mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-23 21:46:27 +02:00
cli: add ppman install and list
This commit is contained in:
parent
e5225f05c9
commit
ff69a28a68
3 changed files with 73 additions and 0 deletions
31
cli/commands/ppman_commands/list.js
Normal file
31
cli/commands/ppman_commands/list.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
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']);
|
||||
|
||||
const repos = await api.list_repos();
|
||||
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
|
||||
const packages = await repos_obj.reduce(async (a, c) => [
|
||||
...await a,
|
||||
...await c.list_packages().catch(x=>{console.log(x); return []})
|
||||
], []);
|
||||
|
||||
const pkg_msg = packages
|
||||
.map(msg_format.color)
|
||||
.join('\n');
|
||||
|
||||
console.log(pkg_msg);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue