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-16 13:27:14 +01:00
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);
})();