UNPKG

2.91 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@heroku-cli/command");
4const cli_ux_1 = require("cli-ux");
5const lodash_1 = require("lodash");
6const buildpack_registry_1 = require("@heroku/buildpack-registry");
7class Search extends command_1.Command {
8 async run() {
9 let { args, flags } = this.parse(Search);
10 let registry;
11 let searchResults;
12 registry = new buildpack_registry_1.BuildpackRegistry();
13 if (args.term) {
14 let uniqueBuildpacks = new Map();
15 let array = ((await registry.search(args.term, undefined, undefined)).unwrapOr([]))
16 .concat((await registry.search(undefined, args.term, undefined)).unwrapOr([]))
17 .concat((await registry.search(undefined, undefined, args.term)).unwrapOr([]));
18 array
19 .forEach((element) => {
20 uniqueBuildpacks.set(`${element.namespace}/${element.name}`, element);
21 });
22 searchResults = [...uniqueBuildpacks.values()];
23 }
24 else {
25 searchResults = (await registry.search(flags.namespace, flags.name, flags.description)).unwrapOr([]);
26 }
27 let buildpacks = searchResults.map((buildpack) => {
28 return {
29 buildpack: `${buildpack.namespace}/${buildpack.name}`,
30 category: buildpack.category,
31 description: buildpack.description
32 };
33 });
34 const trunc = (value, _) => lodash_1.truncate(value, { length: 35, omission: '…' });
35 let displayTable = (buildpacks) => {
36 cli_ux_1.cli.table(buildpacks, {
37 columns: [
38 { key: 'buildpack', label: 'Buildpack' },
39 { key: 'category', label: 'Category' },
40 { key: 'description', label: 'Description', format: trunc }
41 ]
42 });
43 };
44 if (buildpacks.length === 0) {
45 cli_ux_1.cli.log('No buildpacks found');
46 }
47 else if (buildpacks.length === 1) {
48 displayTable(buildpacks);
49 cli_ux_1.cli.log('\n1 buildpack found');
50 }
51 else {
52 displayTable(buildpacks);
53 cli_ux_1.cli.log(`\n${buildpacks.length} buildpacks found`);
54 }
55 }
56}
57Search.description = 'search for buildpacks';
58Search.flags = {
59 namespace: command_1.flags.string({ description: 'buildpack namespaces to filter on using a comma separated list' }),
60 name: command_1.flags.string({ description: 'buildpack names to filter on using a comma separated list ' }),
61 description: command_1.flags.string({ description: 'buildpack description to filter on' })
62};
63Search.args = [
64 {
65 name: 'term',
66 description: 'search term that searches across name, namespace, and description'
67 }
68];
69exports.default = Search;