cli: new api-client version

This commit is contained in:
Thomas Hobson 2021-03-06 19:27:13 +13:00
parent f9640d6166
commit fe2e2f4e30
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
2 changed files with 7 additions and 24 deletions

View File

@ -16,22 +16,12 @@ const msg_format = {
exports.handler = async function(argv){ 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 opts = {
language: argv['language'],
version: argv['language-version']
};
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug))); const install = await api.install_package(opts).catch(x=>x);
const repo_pkgs = await Promise.all(repos_obj.map(
async repo => ({
repo: repo,
packages: await repo.list_packages().catch(_=>[])
})
))
const repo = repo_pkgs.find(r => r.packages.find(p=>p.language == argv['language'] && p.language_version == argv['language-version']))
if(!repo) throw Error("Package could not be located")
const package = await repo.repo.get_package(argv['language'], argv['language-version'])
const install = await package.install().catch(x=>x)
console.log(msg_format.color(install)); console.log(msg_format.color(install));
} }

View File

@ -16,15 +16,8 @@ const msg_format = {
exports.handler = async function(argv){ 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 packages = await api.list_packages();
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
const packages = await repos_obj.reduce(async (accumulator, repo) => [
...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)