mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
validate json instead of a json header, and lots of cleanup
This commit is contained in:
parent
0da1cd5867
commit
de449c6d56
15 changed files with 272 additions and 269 deletions
|
@ -8,7 +8,7 @@ exports.aliases = ['run'];
|
|||
exports.describe = 'Executes file with the specified runner';
|
||||
|
||||
exports.builder = {
|
||||
languageVersion: {
|
||||
version: {
|
||||
string: true,
|
||||
desc: 'Set the version of the language to use',
|
||||
alias: ['l'],
|
||||
|
@ -38,7 +38,7 @@ exports.builder = {
|
|||
}
|
||||
};
|
||||
|
||||
exports.handler = async function(argv) {
|
||||
exports.handler = async (argv) => {
|
||||
const files = [...(argv.files || []),argv.file]
|
||||
.map(file_path => {
|
||||
return {
|
||||
|
@ -63,7 +63,7 @@ exports.handler = async function(argv) {
|
|||
run_timeout: argv.rt
|
||||
};
|
||||
|
||||
let { data: response } = await argv.axios.post('/api/v1/execute', request);
|
||||
let { data: response } = await argv.axios.post('/api/v2/execute', request);
|
||||
|
||||
const step = (name, ctx) => {
|
||||
console.log(chalk.bold(`== ${name} ==`));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
exports.command = 'ppman'
|
||||
exports.aliases = ['pkg']
|
||||
exports.describe = 'Package Manager'
|
||||
exports.command = 'ppman';
|
||||
exports.aliases = ['pkg'];
|
||||
exports.describe = 'Package Manager';
|
||||
|
||||
exports.builder = yargs => yargs
|
||||
.commandDir('ppman_commands')
|
||||
.demandCommand()
|
||||
.demandCommand();
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['install <language> [language-version]']
|
||||
exports.aliases = ['i']
|
||||
exports.describe = 'Installs the named package'
|
||||
|
||||
exports.command = ['install <language> [language-version]'];
|
||||
exports.aliases = ['i'];
|
||||
exports.describe = 'Installs the named package';
|
||||
|
||||
const msg_format = {
|
||||
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'monochrome': p => `Installation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'json': JSON.stringify
|
||||
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p => `Installation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
exports.handler = async function({axios, language, languageVersion}){
|
||||
try{
|
||||
const install = await axios.post(`/api/v1/packages/${language}/${languageVersion || '*'}`)
|
||||
exports.handler = async ({ axios, language, version }) => {
|
||||
try {
|
||||
const install = await axios.post(`/api/v2/packages/${language}/${version || '*'}`);
|
||||
|
||||
console.log(msg_format.color(install.data));
|
||||
}catch({response}){
|
||||
} catch ({ response }) {
|
||||
console.error(response.data.message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
//const fetch = require('node-fetch');
|
||||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['list']
|
||||
exports.aliases = ['l']
|
||||
exports.describe = 'Lists all available packages'
|
||||
|
||||
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('/api/v1/packages');
|
||||
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 ({ axios }) => {
|
||||
const packages = await axios.get('/api/v2/packages');
|
||||
|
||||
const pkg_msg = packages.data
|
||||
.map(msg_format.color)
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['uninstall <language> [language-version]']
|
||||
exports.aliases = ['u']
|
||||
exports.describe = 'Uninstalls the named package'
|
||||
|
||||
exports.command = ['uninstall <language> [language-version]'];
|
||||
exports.aliases = ['u'];
|
||||
exports.describe = 'Uninstalls the named package';
|
||||
|
||||
const msg_format = {
|
||||
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'monochrome': p => `Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'json': JSON.stringify
|
||||
color: p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
monochrome: p => `Uninstallation ${p.language ? 'succeeded' : 'failed: ' + p.message}`,
|
||||
json: JSON.stringify
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
exports.handler = async function({axios, language, languageVersion}){
|
||||
try{
|
||||
const uninstall = await axios.delete(`/api/v1/packages/${language}/${languageVersion || '*'}`)
|
||||
exports.handler = async ({ axios, language, version }) => {
|
||||
try {
|
||||
const uninstall = await axios.delete(`/api/v2/packages/${language}/${version || '*'}`)
|
||||
|
||||
console.log(msg_format.color(uninstall.data));
|
||||
}catch({response}){
|
||||
} catch ({ response }) {
|
||||
console.error(response.data.message)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const axios = require('axios').default;
|
||||
|
||||
const axios_instance = function(argv){
|
||||
const axios_instance = argv => {
|
||||
argv.axios = axios.create({
|
||||
baseURL: argv['piston-url']
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ require('yargs')(process.argv.slice(2))
|
|||
string: true
|
||||
})
|
||||
.middleware(axios_instance)
|
||||
.scriptName("piston")
|
||||
.scriptName('piston')
|
||||
.commandDir('commands')
|
||||
.demandCommand()
|
||||
.help()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue