Namespaced Terminal Client Commands
This module aims to provide an easy and structured way to create modular commands for Node commandline clients and load them only on demand.
It extends a client object with an execute
function which can execute modules created with a declared namespaced convention. Each namespaced module must contain a method called invoke
. This method runs always in context of the client object.
Usage
Create a command with arguments
"test-client-commands/***clientcommand.***testcommand.open-with-arguments.js"
"use strict"; var { return this;}; Cmdprototype { // runs in context of client. return "This testcommand is using open called from " + thisid + " (" + name1 + "," + name2 + "," + name3 + ")";}; moduleexports = Cmd;
Extend a terminal client
var NTCC = ;var ntcc = ; var { thisid = "A Testing Client"; return this;};var testClient = ; ntcc;
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
;
For more examples see the test-client-commands and the tests.
A more realistic usecase
testClient__;testClient__;testClient__;testClient__;
I prefer to use this module in association with minimist.