cli: code cleanup

This commit is contained in:
Thomas Hobson 2021-03-05 19:40:47 +13:00
parent e57e56037c
commit d1b41e3c2f
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 19 additions and 14 deletions

View File

@ -50,16 +50,16 @@ exports.handler = async function(argv){
})) || ""; })) || "";
const response = await api.run_job( const response = await api.run_job({
argv.language, language: argv.language,
argv['language-version'], version: argv['language-version'],
files, files: files,
argv.file, main: argv.file,
argv.args, arsg: argv.args,
stdin, stdin,
argv.ct, compile_timeout: argv.ct,
argv.rt run_timeout: argv.rt
) })
function step(name, ctx){ function step(name, ctx){
console.log(chalk.bold(`== ${name} ==`)) console.log(chalk.bold(`== ${name} ==`))

View File

@ -17,11 +17,13 @@ exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']); const api = new PistonEngine(argv['piston-url']);
const repos = await api.list_repos(); const repos = await api.list_repos();
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug))); const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
const repo_pkgs = await Promise.all(repos_obj.map( const repo_pkgs = await Promise.all(repos_obj.map(
async repo => ({ async repo => ({
repo: repo, repo: repo,
packages: await repo.list_packages().catch(x=>[]) packages: await repo.list_packages().catch(_=>[])
}) })
)) ))

View File

@ -17,11 +17,14 @@ exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']); const api = new PistonEngine(argv['piston-url']);
const repos = await api.list_repos(); const repos = await api.list_repos();
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug))); const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
const packages = await repos_obj.reduce(async (a, c) => [
...await a, const packages = await repos_obj.reduce(async (accumulator, repo) => [
...await c.list_packages().catch(x=>{console.log(x); return []}) ...await accumulator,
], []); ...await repo.list_packages()
.catch(x=>{console.log(x); return []})
], []); // Loops over repos, listing packages and flattening them into a single array
const pkg_msg = packages const pkg_msg = packages
.map(msg_format.color) .map(msg_format.color)