piston/cli/execute

33 lines
815 B
Plaintext
Raw Normal View History

2021-01-16 13:27:14 +01:00
#!/usr/bin/env node
2021-01-16 13:14:17 +01:00
2021-01-25 19:54:39 +01:00
const { execute } = require('../lxc/execute.js');
2021-01-16 13:27:14 +01:00
const { readFileSync } = require('fs');
2021-01-25 19:54:39 +01:00
const languages = require('../config/languages.json');
2021-01-16 13:27:14 +01:00
const [languageName, sourceFile, ...args] = process.argv.slice(2);
(async () => {
if (!languageName) {
console.error('Provide a language name');
return;
}
2021-01-25 19:54:39 +01:00
2021-01-16 13:27:14 +01:00
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;
}
2021-01-16 18:41:41 +01:00
const { output } = await execute(language, source, '', args);
2021-01-16 13:27:14 +01:00
console.log(output);
})();