Fix aliases, update readme
This commit is contained in:
parent
f78aa34c10
commit
f685bdc751
33
cli/execute
33
cli/execute
|
@ -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);
|
||||
})();
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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);
|
||||
})();
|
|
@ -47,7 +47,7 @@ See `var/install.txt` for how to create a new LXC container and install all of t
|
|||
software.
|
||||
|
||||
#### CLI Usage
|
||||
- `lxc/execute [language] [file path] [args]`
|
||||
- `cli/execute [language] [file path] [args]`
|
||||
|
||||
#### API Usage
|
||||
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",
|
||||
"aliases": ["awk"],
|
||||
"version": "1.3.3"
|
||||
},
|
||||
{
|
||||
"name": "bash",
|
||||
"aliases": ["bash"],
|
||||
"version": "4.4.20"
|
||||
},
|
||||
{
|
||||
"name": "c",
|
||||
"aliases": ["c"],
|
||||
"version": "7.5.0"
|
||||
}
|
||||
]
|
||||
|
@ -130,8 +133,7 @@ HTTP/1.1 400 Bad Request
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"code": "unsupported_language",
|
||||
"message": "whatever is not supported by Piston"
|
||||
"message": "Provided language is not supported by Piston"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue