0.3.1 • Published 7 years ago

cmdrouter v0.3.1

Weekly downloads
23
License
MIT
Repository
github
Last release
7 years ago

Intro

Simple command line router that maps command line arguments to javascript function name and params. Very simple mapping at this point (first param is the method name, subsequent ones are passed as param).

Note: From v0.2.x now node.js > 8 is required.

Note: From v0.3.x needs to import as const { router } = require("cmdrouter"); (rather than the 0.2.x const router = require("cmdrouter");)

usage

testcmd.js

const { router } = require("cmdrouter");
// or import { router } from 'cmdrouter'

// create a router instance with the name/function dictionary, 
// and call route() to route from the process.argv
router({_default, helloWorld, hello}).route();

function _default(){
    console.log("no command, _default function executed");
}

function helloWorld(){
    console.log("hello world");
}

function hello(name){
    console.log(`Hello ${name}`);
}

async function asyncWork(){
    var a = yield 12;
    var b = await getPromiseForB(); // returns a promise that will resolve with 8.
    console.log(`a + b = ${a + b}`);
}

From command line:

> node testcmd
no command, _default function executed
> node testcmd hellowWorld
hello world
> node testcmd hello John
Hello John
> node asyncWork
a + b = 20
0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

9 years ago