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

Commit

Permalink
Added the --config option.
Browse files Browse the repository at this point in the history
Closes #1.
  • Loading branch information
mcollina committed Feb 20, 2013
1 parent 296b1be commit 6b061ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

var pkg = require("../package");
var program = require("commander");
var path = require("path");

program
.version(pkg.version)
.option("-p, --port <n>", "the port to listen to", parseInt)
.option("--parent-port <n>", "the parent port to connect to", parseInt)
.option("--parent-host <s>", "the parent host to connect to")
.option("--parent-prefix <s>", "the prefix to use in the parent broker")
.option("-c, --config <c>", "the config file to use (override every other options)")
.option("-v, --verbose", "equal to DEBUG=mosca")
.option("--very-verbose", "equal to DEBUG=mosca,ascoltatori:*");

Expand Down Expand Up @@ -51,5 +53,9 @@ module.exports = function cli(argv) {

opts.backend.prefix = program.parentPrefix;

if(program.config) {
opts = require(path.join(process.cwd(), program.config));
}

return new Server(opts);
};
10 changes: 10 additions & 0 deletions test/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,14 @@ describe(mosca.cli, function () {
done();
});
});

it("should support a config option", function (done) {
args.push("--config");
args.push("test/sample_config.js");
server = mosca.cli(args);
server.on("ready", function () {
expect(server.opts).to.eql(require("./sample_config"));
done();
});
});
});
8 changes: 8 additions & 0 deletions test/sample_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module.exports = {
port: 2883,
backend: {
type: "mqtt",
port: 3833
}
};

0 comments on commit 6b061ed

Please sign in to comment.