Skip to content

Commit 61e457f

Browse files
W0lfw00dvutran
authored andcommitted
Added search command to the cli (#42)
* Add search command to the cli * api.search now returns an array * - Update the dext-core-utils dep to v0.4.0 - Refactored the search command to add descriptions and only run console.log once * - Update the dext-core-utils dep to v0.4.1 - Don't search if no search term is provide
1 parent 5992f1e commit 61e457f

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

cli.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,37 @@ const chalk = require('chalk');
66
const ora = require('ora');
77
const { api, utils } = require('dext-core-utils');
88

9+
args.command(['search', 's'], 'Seach for plugins or themes.', (name, sub) => {
10+
const searchTerm = sub[0];
11+
if (!searchTerm) {
12+
console.log(chalk.yellow('Search must be called with an search term'));
13+
return;
14+
}
15+
16+
const spinner = ora(chalk.green(`Searching for "${searchTerm}"...`)).start();
17+
return api.search(searchTerm)
18+
.then((results) => {
19+
spinner.color = 'green';
20+
spinner.text = chalk.green(`Results for "${searchTerm}":`);
21+
spinner.succeed();
22+
23+
let resultsMessage;
24+
if (results.length) {
25+
resultsMessage = results.reduce((prev, result) =>
26+
`${prev}- ${result.name}: ${result.desc}\n`, ''
27+
);
28+
} else {
29+
resultsMessage = chalk.yellow('no packages found');
30+
}
31+
console.log(resultsMessage);
32+
})
33+
.catch((err) => {
34+
spinner.color = 'red';
35+
spinner.text = chalk.red(err);
36+
spinner.fail();
37+
});
38+
});
39+
940
args.command(['install', 'i'], 'Install a new plugin or theme.', (name, sub) => {
1041
const plugin = sub[0];
1142
const spinner = ora(chalk.green(`${plugin} : Installing...`)).start();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"args": "^2.1.0",
2020
"chalk": "^1.1.3",
21-
"dext-core-utils": "^0.3.0",
21+
"dext-core-utils": "^0.4.1",
2222
"ora": "^0.3.0"
2323
},
2424
"devDependencies": {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ del@^2.0.2:
309309
pinkie-promise "^2.0.0"
310310
rimraf "^2.2.8"
311311

312-
dext-core-utils@^0.3.0:
313-
version "0.3.0"
314-
resolved "https://registry.yarnpkg.com/dext-core-utils/-/dext-core-utils-0.3.0.tgz#cf0d07326ce31a2a4650d7ed72b43dc83722e92f"
312+
dext-core-utils@^0.4.1:
313+
version "0.4.1"
314+
resolved "https://registry.yarnpkg.com/dext-core-utils/-/dext-core-utils-0.4.1.tgz#b7b6e2d2c3b882eddd528fe27a682c6c19a8212f"
315315
dependencies:
316316
conf "^0.11.2"
317317
cross-spawn "^4.0.2"

0 commit comments

Comments
 (0)