-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.coffee
More file actions
82 lines (69 loc) · 2.39 KB
/
Copy pathbin.coffee
File metadata and controls
82 lines (69 loc) · 2.39 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
76
77
78
79
80
81
82
require("source-map-support").install()
yargs = require("yargs")
onUp = require("on-up")
dbin = require("./index.js")
path = require("path")
fs = require("fs")
args = yargs
.usage("Usage: $0 [command] [-options]")
.example("$0 -rt", "same as $ dbin start --transactor --rest")
.example("$0 gets-ok?", "wait-up for the servers to start / answer with yes or no (whether they did)")
.string("o").alias("o", "config").describe("o", "from file, merged into defaults.json")
.boolean(["p", "t", "r", "c"])
.alias("p", "print").describe("p", "prints the config")
.alias("t", "transactor").describe("t", "applies to the transactor")
.alias("r", "rest").describe("r", "applies to the rest server")
.alias("c", "console").describe("c", "applies to the console client")
.argv
try
# setup relative config options path unless it starts with / (i.e. is absolute)
if args.o? and args.o[0] != '/' then args.o = path.join process.cwd(), args.o
d = dbin.use(if args.o? then require(args.o))
catch error
console.log "Bad options --config '#{args.o}'."
console.log "The file must be / export valid json."
console.log error
process.exit 1
if args.p
console.log()
console.log d.cfg
console.log()
# the first arg is the command, defaults to start
cmd = if args._.length then args._[0] else "start"
cmds =
start: "the default -- starts the options-specified servers"
"gets-ok?": "get the rest api alias and report with a yes or not"
"?, help": "this help"
help = (message) ->
if message
console.log(message)
console.log()
console.log yargs.help()
console.log "Commands:"
for cmd of cmds
console.log " #{cmd} \t#{cmds[cmd]}"
console.log()
switch cmd
when "start"
unless args.t or args.r or args.c
help("Don't know what to start.")
else
if args.t then d.run("transactor")
if args.r then d.run("rest")
if args.c
if d.cfg.edition is "pro" or fs.existsSync(d.cfg.console.path)
d.run("console")
else
console.log "No console found at #{d.cfg.console.path}
- please download and install it there or else set console.path accordingly."
process.exit 1
when "gets-ok?"
onUp {req: {uri: d.cfg.rest.base}, dots: true, patience: 70000}, (res) ->
if res.statusCode is 200
console.log "yes"
process.exit 0
else
console.log "not"
process.exit 1
when "?", "help"
help()