Skip to content

Commit

Permalink
Added --db option to CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Aug 5, 2013
1 parent b6f7d62 commit 7af74aa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $ ./bin/ponte --help
-V, --version output the version number
-m, --mqtt-port <n> the mqtt port to listen to
-p, --http-port <n> the hqtt port to listen to
-d, --db <path> the path were to store the database
-c, --config <c> the config file to use (override every other
option)
-v, --verbose set the bunyan log to INFO
Expand Down Expand Up @@ -130,6 +131,7 @@ These are the new features you should expect in the coming
months:

* [ ] Better bootstrap sequence.
* [ ] Allow and document embedding inside other Node apps.
* [ ] Add Web Hooks support.
* [ ] Document configuration options.
* [ ] Add WebSocket and Server-Sent Events support.
Expand Down
8 changes: 8 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function(args, done) {
.version(pkg.version)
.option("-m, --mqtt-port <n>", "the mqtt port to listen to", parseInt)
.option("-p, --http-port <n>", "the mqtt port to listen to", parseInt)
.option("-d, --db <path>", "the path were to store the database")
.option("-c, --config <c>", "the config file to use (override every other option)")
.option("-v, --verbose", "set the bunyan log to INFO")
.option("--very-verbose", "set the bunyan log to DEBUG");
Expand All @@ -29,6 +30,8 @@ module.exports = function(args, done) {
},
mqtt: {
port: program.mqttPort
},
persistence: {
}
};

Expand All @@ -38,6 +41,11 @@ module.exports = function(args, done) {
opts.logger.level = 20;
}

if (program.db) {
opts.persistence.path = program.db;
opts.persistence.type = "level";
}

if (program.config) {
opts = require(path.resolve(program.config));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ var persistences = {

module.exports = function(opts, done) {
var factory = persistences[opts.type] || persistences.memory;
done(null, factory(opts, done));
delete opts.type;
done(null, factory(opts));
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"sinon": "~1.7.3",
"mocha": "~1.12.0",
"jshint": "~2.1.4",
"supertest": "~0.7.1"
"supertest": "~0.7.1",
"tmp": "0.0.20"
},
"dependencies": {
"express": "~3.3.4",
Expand Down
20 changes: 20 additions & 0 deletions test/cli_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

var ponte = require("../");
var async = require("async");
var tmp = require("tmp");
var mosca = require("mosca");

describe("ponte.cli", function() {

Expand Down Expand Up @@ -118,4 +120,22 @@ describe("ponte.cli", function() {
expect(server.options.logger).to.have.property("name", "Config Test Logger");
});
});

it("should create a leveldb with the --db flag", function(done) {

tmp.dir(function (err, path, fd) {
if (err) {
done(err);
return;
}

args.push("--db");
args.push(path);

startServer(done, function(server) {
expect(server.persistence).to.be.instanceOf(mosca.persistence.LevelUp);
expect(server.persistence.options.path).to.eql(path);
});
});
});
});

0 comments on commit 7af74aa

Please sign in to comment.