-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
96 lines (87 loc) · 2.72 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
87
88
89
90
91
92
93
94
95
96
'use strict';
var create = require('./');
function noOp() {}
module.exports = function() {
this
.title('Create BEM entity').helpful()
.opt()
.name('level').short('l').long('level')
.title('level directory path')
.end()
.opt()
.name('block').short('b').long('block')
.title('block name, required')
.arr()
.end()
.opt()
.name('elem').short('e').long('elem')
.title('element name')
.arr()
.end()
.opt()
.name('mod').short('m').long('mod')
.title('modifier name')
.arr()
.end()
.opt()
.name('val').short('v').long('val')
.title('modifier value')
.arr()
.end()
.opt()
.name('addTech').short('t').long('add-tech')
.title('add tech')
.arr()
.end()
.opt()
.name('forceTech').short('T').long('force-tech')
.title('use only specified tech')
.arr()
.end()
.opt()
.name('noTech').short('n').long('no-tech')
.title('exclude tech')
.arr()
.end()
.opt()
.name('content').short('c').long('content')
.title('the content of the file')
.arr()
.end()
.opt()
.name('force').short('f').long('force')
.title('force files creation')
.flag()
.end()
.arg()
.name('entities').title('Entities')
.arr()
.end()
.act(function(opts, args) {
var options = {},
techs = opts.addTech || [];
if (opts.forceTech) {
options.onlyTech = opts.forceTech;
}
if (opts.noTech) {
options.excludeTech = opts.noTech;
}
if (opts.force) {
options.forceRewrite = opts.force;
}
if (opts.content) {
// if used "-c" without value use stdin as content source
options.fileContent = (opts.content[0] !== undefined) ? opts.content.join() : process.stdin;
}
if (args.entities) {
return create(args.entities, opts.level, techs, options).then(noOp);
}
opts.block && create([{
block: opts.block[0],
elem: opts.elem && opts.elem[0],
modName: opts.mod && opts.mod[0],
modVal: opts.val ? opts.val[0] : Boolean(opts.mod)
}], opts.level, techs, options).then(noOp);
})
.end();
};