-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·75 lines (60 loc) · 1.26 KB
/
index.js
File metadata and controls
executable file
·75 lines (60 loc) · 1.26 KB
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
#!/usr/bin/env node
var minimist = require('minimist')
, json = require('prettyjson')
var flags = require('./config/flags')
var argv = minimist(process.argv.slice(2))
if (argv.client) {
request = require(argv.client)
}
else {
request = require('@request/client')
}
if (argv.h || argv.help) {
console.log(json.render(flags, {
keysColor: 'blue',
stringColor: 'grey'
}))
process.exit()
}
console.log()
function pick (a, b) {
if (typeof a === 'string') {
return a
}
else if (typeof b === 'string') {
return b
}
if (typeof a === 'boolean') {
return a
}
else if (typeof b === 'boolean') {
return b
}
}
function parse (str) {
try {
return eval('o='+str)
}
catch (e) {
return str
}
}
var options = {
// for now put a callback function by default
// so that the response body log events are handled
callback: function () {}
}
for (var flag in flags) {
var shorthand = flag.replace(/^-(.*),.*/, '$1')
, option = flag.replace(/.*--(.*)/, '$1')
if (!argv[shorthand] && !argv[option]) continue
var value = pick(argv[shorthand], argv[option])
value = parse(value)
if (option === 'method') {
options[option] = value.toUpperCase()
}
else {
options[option] = value
}
}
request(options)