Add command line configuration of config file
This commit is contained in:
parent
d336575067
commit
d6d2efe531
|
@ -3,6 +3,7 @@ Q = require "q"
|
|||
http = require "http"
|
||||
express = require "express"
|
||||
winston = require "winston"
|
||||
optimist = require "optimist"
|
||||
|
||||
{ SubscriptionBroker } = require "./lib/subscription-broker"
|
||||
{ SocketIOConsumer } = require "./lib/consumers"
|
||||
|
@ -82,8 +83,27 @@ class exports.ActivePush
|
|||
delete object.name
|
||||
res.json health
|
||||
|
||||
exports.main = (args) ->
|
||||
configuration = config.loadConfiguration(args[0])
|
||||
exports.main = ->
|
||||
options = optimist
|
||||
.usage("Start ActivePush server.\nUsage: activepush [OPTIONS] [ENVIRONMENT]")
|
||||
.boolean(["h", "v"])
|
||||
.alias("c", "config")
|
||||
.describe("c", "Specify a configuration file")
|
||||
.alias("h", "help")
|
||||
.describe("h", "Show command line options and exit")
|
||||
.alias("v", "version")
|
||||
.describe("v", "Show version and exit")
|
||||
|
||||
if options.argv.help
|
||||
options.showHelp()
|
||||
process.exit()
|
||||
if options.argv.version
|
||||
console.log "v" + require("#{__dirname}/package.json").version
|
||||
process.exit()
|
||||
|
||||
configName = options.argv.config or options.argv._[0]
|
||||
|
||||
configuration = config.loadConfiguration(configName)
|
||||
activepush = new exports.ActivePush(configuration)
|
||||
activepush.start().then ->
|
||||
activepush.logger.info "Started with environment: #{activepush.config.environment}"
|
||||
|
@ -92,6 +112,7 @@ exports.main = (args) ->
|
|||
activepush.stop().then ->
|
||||
process.exit(1)
|
||||
.done()
|
||||
.done()
|
||||
|
||||
if require.main is module
|
||||
exports.main(process.argv[2..]).done()
|
||||
exports.main()
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env coffee
|
||||
|
||||
require("../activepush").main process.argv[2..]
|
||||
require("../activepush").main()
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
|
||||
require "js-yaml"
|
||||
path = require "path"
|
||||
merge = require "deepmerge"
|
||||
|
||||
# If name matches ^\w+$ then use one of the built-in configurations,
|
||||
# otherwise assume it's a path.
|
||||
exports.loadConfiguration = (name) ->
|
||||
name = name or process.env["NODE_ENV"] or "development"
|
||||
if /^\w+$/.test(name)
|
||||
config = path.resolve "#{__dirname}/../config/#{name}.yml"
|
||||
else
|
||||
config = path.resolve ".", name
|
||||
deflt = require("#{__dirname}/../config/default.yml") or {}
|
||||
overlay = require("#{__dirname}/../config/#{name}.yml") or {}
|
||||
overlay = require(config) or {}
|
||||
merge(merge(deflt, overlay), environment: name)
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
"express": "~3.3.4",
|
||||
"deepmerge": "~0.2.7",
|
||||
"winston": "~0.7.2",
|
||||
"stompit": "~0.9.0"
|
||||
"stompit": "~0.9.0",
|
||||
"optimist": "~0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "~1.12.0",
|
||||
|
|
Loading…
Reference in New Issue