ntcc
v1.0.1
Published
[](https://www.npmjs.org/package/ntcc) [](https://travis-ci.org/s-a/ntcc) [ {
return this;
};
Cmd.prototype.invoke = function(name1,name2,name3) {
// runs in context of client.
return "This testcommand is using open called from " + this.id + " (" + name1 + "," + name2 + "," + name3 + ")";
};
module.exports = Cmd;
Extend a terminal client
var NTCC = require("ntcc");
var ntcc = new NTCC();
var TestClient = function() {
this.id = "A Testing Client";
return this;
};
var testClient = new TestClient();
ntcc.extend({
client: testClient,
dir: path.join(__dirname, "..", "test-client-commands"),
namespacePrefix: "clientcommand."
});
console.log(testClient.__)
yields:
- execute() | Method to exec a command.
- listCommands() | Usefull to provide a commandline help.
- getCommandFilename() | returns a filename for a given command namespace.
Invoke the test command
it("should execute testcommand.open-with-arguments to pass custom arguments", function() {
var args = ["arg1", "arg2", "argN"];
var string = testClient.__.execute(["testcommand", "open-with-arguments"], args);
string.should.equal("This testcommand is using open called from " + testClient.id + " (" + args.join(",") + ")");
});
For more examples see the test-client-commands and the tests.
A more realistic usecase
testClient.__.execute(["open", "db", "connection"], ["connection-1"]);
testClient.__.execute(["close", "db", "connection"], ["connection-1"]);
testClient.__.execute(["new", "db", "connection"]);
testClient.__.execute(["remove", "db", "connection"], ["connection-1"]);
I prefer to use this module in association with minimist.