cli: new api-client version
This commit is contained in:
parent
f9640d6166
commit
fe2e2f4e30
|
@ -16,22 +16,12 @@ const msg_format = {
|
|||
exports.handler = async function(argv){
|
||||
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 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)
|
||||
const install = await api.install_package(opts).catch(x=>x);
|
||||
|
||||
console.log(msg_format.color(install));
|
||||
}
|
|
@ -16,15 +16,8 @@ const msg_format = {
|
|||
exports.handler = async function(argv){
|
||||
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
|
||||
.map(msg_format.color)
|
||||
|
|
Loading…
Reference in New Issue