-
Notifications
You must be signed in to change notification settings - Fork 16
/
cli.js
executable file
·54 lines (44 loc) · 1.04 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
#!/usr/bin/env node
'use strict';
var cp = require('copy-paste');
var yod = require('./src/yod-mock');
var copy, caller, params, args = process.argv.slice(2);
if (args.indexOf('-c') >= 0) {
copy = true;
args.splice(args.indexOf('-c'), 1);
}
if (!args.length) {
console.log('\r\n Usage:');
console.log('\r\n yod [-c] generator\r\n');
console.log(Object.keys(yod.types).join('\t'), '\r\n');
} else {
caller = args.shift();
params = false;
args.forEach(function(arg) {
if (arg[0] !== '.') {
if (!params) {
params = [];
}
params.push(arg);
} else {
if (params) {
caller += '(' + params.join(', ') + ')';
}
caller += arg;
params = false;
}
});
if (params) {
caller += '(' + params.join(', ') + ')';
}
caller = caller.replace(/^@/, '');
try {
caller = yod('@' + yod._.capitalize(caller));
console.log();
console.log(caller);
console.log();
if (copy) { cp.copy(caller); }
} catch (e) {
console.log('\nError: ' + e.message + '\n');
}
}