mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
cli: switch to axios
This commit is contained in:
parent
a1536ffe56
commit
5a05537a7f
6 changed files with 48 additions and 46 deletions
|
@ -1,4 +1,4 @@
|
|||
const fetch = require('node-fetch');
|
||||
//const fetch = require('node-fetch');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
|
@ -59,14 +59,8 @@ exports.handler = async function(argv){
|
|||
run_timeout: argv.rt
|
||||
};
|
||||
|
||||
const response = await fetch(argv['piston-url'] + '/jobs', {
|
||||
method: 'post',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(request)
|
||||
})
|
||||
.then(res=>res.json())
|
||||
.then(res=>{if(res.data)return res.data; throw new Error(res.message)})
|
||||
.catch(x=>x);
|
||||
let response = await argv.axios.post('/jobs', request);
|
||||
response = response.data
|
||||
|
||||
function step(name, ctx){
|
||||
console.log(chalk.bold(`== ${name} ==`))
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['install <language> <language-version>']
|
||||
|
@ -13,15 +12,12 @@ const msg_format = {
|
|||
|
||||
}
|
||||
|
||||
exports.handler = async function(argv){
|
||||
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);
|
||||
|
||||
|
||||
console.log(msg_format.color(install));
|
||||
exports.handler = async function({axios, language, languageVersion}){
|
||||
try{
|
||||
const install = await axios.post(`/packages/${language}/${languageVersion}`)
|
||||
|
||||
console.log(msg_format.color(install.data));
|
||||
}catch({response}){
|
||||
console.error(response.data.message)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
const fetch = require('node-fetch');
|
||||
//const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['list']
|
||||
|
@ -13,19 +13,12 @@ const msg_format = {
|
|||
|
||||
}
|
||||
|
||||
exports.handler = async function(argv){
|
||||
const api = new PistonEngine(argv['piston-url']);
|
||||
exports.handler = async function({axios}){
|
||||
|
||||
const packages = await api.list_packages();
|
||||
const packages = await axios.get('/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
|
||||
|
||||
const pkg_msg = packages.data.data.packages
|
||||
.map(msg_format.color)
|
||||
.join('\n');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue