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){
|
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_obj = await Promise.all(repos.repos.map(({slug}) => api.get_repo(slug)));
|
|
||||||
|
|
||||||
const repo_pkgs = await Promise.all(repos_obj.map(
|
const opts = {
|
||||||
async repo => ({
|
language: argv['language'],
|
||||||
repo: repo,
|
version: argv['language-version']
|
||||||
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']))
|
const install = await api.install_package(opts).catch(x=>x);
|
||||||
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));
|
||||||
}
|
}
|
|
@ -15,17 +15,10 @@ 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 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
|
const pkg_msg = packages
|
||||||
.map(msg_format.color)
|
.map(msg_format.color)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
Loading…
Reference in New Issue