Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Merge default options with config files if property not specified #58

Merged
merged 2 commits into from
Sep 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ function start(program, callback) {

var server = null;

var opts = {
var defopts = {
backend: {},
logger: {},
persistence: {
factory: persistence.Memory
}
};

var opts = defopts;

opts.port = program.port;

if (program.parentPort || program.parentHost) {
Expand Down Expand Up @@ -90,6 +92,13 @@ function start(program, callback) {

if (program.config) {
opts = require(path.resolve(program.config));

// merge any unspecified options into opts from defaults (defopts)
Object.keys(defopts).forEach(function(key) {
if(typeof opts[key] === 'undefined') {
opts[key] = defopts[key];
}
});
}

if (program.verbose) {
Expand Down
10 changes: 10 additions & 0 deletions test/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ describe("mosca.cli", function() {
});
});

it("should create necessary default options even if not specified in config file", function(done) {
args.push("-c");
args.push(process.cwd() + "/test/sample_config.js");
args.push("-v");

startServer(done, function(server) {
expect(server.opts).to.have.deep.property("logger.name", "mosca");
});
});

it("should add an user to an authorization file", function(done) {
args.push("adduser");
args.push("myuser");
Expand Down