mirror of
https://github.com/engineer-man/piston.git
synced 2025-05-01 17:36:28 +02:00
cli: merge with api-client
This commit is contained in:
parent
e5000917e8
commit
a1536ffe56
8 changed files with 28 additions and 102 deletions
cli/commands/ppman_commands
|
@ -1,4 +1,4 @@
|
|||
const {PistonEngine} = require('piston-api-client');
|
||||
const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['install <language> <language-version>']
|
||||
|
@ -14,14 +14,14 @@ const msg_format = {
|
|||
}
|
||||
|
||||
exports.handler = async function(argv){
|
||||
const api = new PistonEngine(argv['piston-url']);
|
||||
const install = await fetch(
|
||||
`${argv['piston-url']}/packages/${argv['language']}/${argv['language-version']}`,
|
||||
{method: 'post'}
|
||||
)
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)})
|
||||
.catch(x=>x);
|
||||
|
||||
const opts = {
|
||||
language: argv['language'],
|
||||
version: argv['language-version']
|
||||
};
|
||||
|
||||
const install = await api.install_package(opts).catch(x=>x);
|
||||
|
||||
console.log(msg_format.color(install));
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
const {PistonEngine} = require('piston-api-client');
|
||||
const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['list']
|
||||
|
@ -18,6 +18,12 @@ exports.handler = async function(argv){
|
|||
|
||||
const packages = await api.list_packages();
|
||||
|
||||
const packages = await fetch(argv['piston-url'] + '/packages')
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)});
|
||||
.then(res=>res.packages)
|
||||
.catch(x=>x)
|
||||
|
||||
|
||||
const pkg_msg = packages
|
||||
.map(msg_format.color)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue