Fix aliases, update readme

This commit is contained in:
Vrganj 2021-01-16 13:27:14 +01:00
parent f78aa34c10
commit f685bdc751
4 changed files with 36 additions and 47 deletions

View File

@ -1,3 +1,32 @@
#!/usr/bin/env bash #!/usr/bin/env node
node src $* const { execute } = require('../shared/execute');
const { readFileSync } = require('fs');
const languages = require('../shared/languages.json');
const [languageName, sourceFile, ...args] = process.argv.slice(2);
(async () => {
if (!languageName) {
console.error('Provide a language name');
return;
}
if (!sourceFile) {
console.error('Provide a source file');
return;
}
const source = readFileSync(sourceFile).toString();
const language = languages.find(language => language.aliases.includes(languageName.toLowerCase()));
if (!language) {
console.error(`${languageName} is not supported by Piston`);
return;
}
const { output } = await execute(language, source, args);
console.log(output);
})();

View File

@ -1,12 +0,0 @@
{
"name": "cli",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

View File

@ -1,30 +0,0 @@
const { execute } = require('../../shared/execute');
const { readFileSync } = require('fs');
const languages = require('../../shared/languages.json');
const [languageName, sourceFile, ...args] = process.argv.slice(2);
(async () => {
if (!languageName) {
console.error('Provide a language name');
return;
}
if (!sourceFile) {
console.error('Provide a source file');
return;
}
const source = readFileSync(sourceFile).toString();
const language = languages.find(language => language.name === languageName);
if (!language) {
console.error(`${languageName} is not supported by Piston`);
return;
}
const { output } = await execute(language, source, args);
console.log(output);
})();

View File

@ -47,7 +47,7 @@ See `var/install.txt` for how to create a new LXC container and install all of t
software. software.
#### CLI Usage #### CLI Usage
- `lxc/execute [language] [file path] [args]` - `cli/execute [language] [file path] [args]`
#### API Usage #### API Usage
To use the API, it must first be started. Please note that if root is required to access To use the API, it must first be started. Please note that if root is required to access
@ -79,14 +79,17 @@ Content-Type: application/json
[ [
{ {
"name": "awk", "name": "awk",
"aliases": ["awk"],
"version": "1.3.3" "version": "1.3.3"
}, },
{ {
"name": "bash", "name": "bash",
"aliases": ["bash"],
"version": "4.4.20" "version": "4.4.20"
}, },
{ {
"name": "c", "name": "c",
"aliases": ["c"],
"version": "7.5.0" "version": "7.5.0"
} }
] ]
@ -130,8 +133,7 @@ HTTP/1.1 400 Bad Request
Content-Type: application/json Content-Type: application/json
{ {
"code": "unsupported_language", "message": "Provided language is not supported by Piston"
"message": "whatever is not supported by Piston"
} }
``` ```