From f685bdc7516fc9810e4848ecd799c80e17233c2a Mon Sep 17 00:00:00 2001 From: Vrganj Date: Sat, 16 Jan 2021 13:27:14 +0100 Subject: [PATCH] Fix aliases, update readme --- cli/execute | 33 +++++++++++++++++++++++++++++++-- cli/package.json | 12 ------------ cli/src/index.js | 30 ------------------------------ readme.md | 8 +++++--- 4 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 cli/package.json delete mode 100644 cli/src/index.js diff --git a/cli/execute b/cli/execute index 37a6b35..a62d120 100755 --- a/cli/execute +++ b/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); +})(); diff --git a/cli/package.json b/cli/package.json deleted file mode 100644 index 0166712..0000000 --- a/cli/package.json +++ /dev/null @@ -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" -} diff --git a/cli/src/index.js b/cli/src/index.js deleted file mode 100644 index 02fdd56..0000000 --- a/cli/src/index.js +++ /dev/null @@ -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); -})(); diff --git a/readme.md b/readme.md index 5b2cb85..05f8d93 100644 --- a/readme.md +++ b/readme.md @@ -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" } ```