-
Notifications
You must be signed in to change notification settings - Fork 13
/
helper.coffee
43 lines (34 loc) · 942 Bytes
/
helper.coffee
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
_ = require('underscore')
params = null
task_id = null
config = null
parseCLIData = ->
fs = require('fs')
querystring = require('querystring')
process.argv.forEach (val, index, array) ->
if val == "-payload"
params = fs.readFileSync(process.argv[index + 1], 'utf8')
try
params = JSON.parse(params)
catch e
try
parsed = querystring.parse(params)
if !(Object.keys(parsed).length == 1 && parsed[Object.keys(parsed)[0]] == '')
params = parsed
catch e
if val == "-config"
config = fs.readFileSync(process.argv[index + 1], 'utf8')
try
config = JSON.parse(config)
catch e
if val == "-id"
task_id = process.argv[index + 1]
module.exports.params = ->
parseCLIData() if !params
params
module.exports.taskId = ->
parseCLIData() if !task_id
task_id
module.exports.config = ->
parseCLIData() if !config
config