/
index.js
executable file
·46 lines (36 loc) · 1.14 KB
/
index.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
#!/usr/bin/env node
var program = require('commander');
var lib = require('./my_lib');
function parse10(val) {
// radix 10
return parseInt(val, 10);
}
program.version('1.0.3')
program.command('uuid')
.description('Generate uuid string')
.action(function() {
lib.string_uuid();
});
program.command('hex')
.description('Generate hex random string')
.option('-b, --bytes <value>', 'The number of bytes of hex', parse10, 16)
.action(function(options) {
var bytes = options.bytes;
lib.string_hex(bytes);
});
program.command('hex_array')
.description('Generate hex array. Ex: { 0x01, 0xab, 0x3a }')
.option('-b, --bytes <value>', 'The number of bytes', parse10, 16)
.action(function(options) {
var bytes = options.bytes;
lib.string_hex_array(bytes);
});
program.command('string')
.description('Generate secure random string.')
.option('-l, --length <value>', 'The length of string', parse10, 16)
.action(function(options) {
var length = options.length;
lib.string_secure_random(length);
});
program.parse(process.argv);
if (program.args.length === 0) program.help()