Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
Latest commit
executable file
·56 lines (42 loc) · 1 KB
/
Copy pathcli.js
File metadata and controls
executable file
·56 lines (42 loc) · 1 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
#!/usr/bin/env node
varfs=require('fs')
varprompt=require('prompt')
varJsonObj=require('./')
// not minimist for now
//var minimist = require('minimist')
//var args = minimist(process.argv.slice(2))
varargs=process.argv.slice(2)
varfilename=args[0]
if(typeoffilename!=='string'||!filename){
quit(newError('filename required'))
}
varjsonObj=newJsonObj()
try{
jsonObj.set(require(filename))
}catch(err){}
// https://github.com/fritx/qqlog/blob/dev/bin/qqlog.js#L12
// for no prompt symbols
prompt.start({
message: ' ',
delimiter: ' '
})
askField()
functionaskField(){
prompt.get(['key'],function(err,res){
if(err)returnquit(err)
varkey=res['key']
if(!key)returnquit()
prompt.get(['value'],function(err,res){
if(err)returnquit(err)
varval=res['value']
jsonObj.set(key,val)
// fixme: not a good way to recurse
askField()
})
})
}
functionquit(err){
if(err)throwerr
fs.writeFileSync(filename,jsonObj.format())
process.exit(0)
}