cli: new api-client version
This commit is contained in:
parent
f9640d6166
commit
fe2e2f4e30
|
@ -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));
|
||||
}
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue