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

@ -15,23 +15,13 @@ const msg_format = {
exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']);
const repos = await api.list_repos();
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
const repo_pkgs = await Promise.all(repos_obj.map(
async repo => ({
repo: repo,
packages: await repo.list_packages().catch(_=>[])
})
))
const opts = {
language: argv['language'],
version: argv['language-version']
};
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)
const install = await api.install_package(opts).catch(x=>x);
console.log(msg_format.color(install));
}

View File

@ -15,17 +15,10 @@ const msg_format = {
exports.handler = async function(argv){
const api = new PistonEngine(argv['piston-url']);
const repos = await api.list_repos();
const repos_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
const packages = await api.list_packages();
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
.map(msg_format.color)
.join('\n');