-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
86 lines (81 loc) · 2.15 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
var _ = require('lodash'),
bemNaming = require('@bem/sdk.naming.entity'),
util = require('./lib/util'),
find = require('./lib/find'),
getView = require('./lib/view');
/**
* Executes find process with given cli options and arguments
* @param {Object} opts - cli options
* @param {Object} args - cli arguments
*/
function execute(opts, args) {
var conditions = util.conditionsFromBEMItems(args.entity);
conditions.push(util.conditionsFromOptions(opts));
find(conditions)
.pipe(getView(opts.view)())
.pipe(process.stdout);
}
module.exports = function() {
return this
.title('BEM Tool Find')
.helpful()
.completable()
.arg()
.name('entity')
.title('entity')
.val(function(value) {
return bemNaming.parse(value) ||
this.reject('Passed argument is not valid BEM entity');
})
.arr()
.end()
.opt()
.name('level')
.title('Name of level(s)')
.short('l')
.long('level')
.arr()
.end()
.opt()
.name('block')
.title('Name of block(s)')
.short('b')
.long('block')
.arr()
.end()
.opt()
.name('element')
.title('Name of element(s)')
.short('e')
.long('element')
.arr()
.end()
.opt()
.name('modifier')
.title('Name of modifier(s)')
.short('m')
.long('mod')
.arr()
.end()
.opt()
.name('tech')
.title('Name of tech(s)')
.short('t')
.long('tech')
.arr()
.end()
.opt()
.name('view')
.title('Type of output')
.short('v')
.long('view')
.val(function(value) {
if(!_.includes(['plain', 'table', 'tree'], value))
value = 'plain';
return value;
})
.def('plain')
.end()
.act(execute);
};