Skip to content

peymanmortazavi/cmd-liner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cmd-liner

NPM version Downloads

Node.js library to help build awesome command line tools. Don't waste your time learning argv and parsing command strings. Easily define hierarchy of your commands using JavaScript objects.

Installation

$ npm install cmd-liner

Features

  • Hierarchical (nested) commands.
  • Easily provide documentation for every one of the commands.
  • Handle errors when you want to.

Quick Start

var cmdliner = require('cmd-liner');

Now you need to create your commands object.

var commands = {};
commands.say = {
  action: function(cmd) {
    console.log('I say ' + cmd.args[0]);
  },
  argsCount: 1,
  desc: "A good description for the command 'say' :D"
};
commands.command2 = {
  commands: {
    is: function(optimist) {
      console.log('I can use optimist to parse arguments');
    }
  },
  nohandler: function() { console.error('No handler for this command :(')); }
}

Then you can initialize the command liner.

cmdliner.init(commands);

Now you can test your code:

$ node mycode.js say Hi
I say Hi

Take a look at https://github.com/substack/node-optimist. Every 'action' will be called with the instance of 'optimist' so you can parse arguments and create aliases. If your requirement needs no such thing, don't worry about it.

To-Do

  • Allow non-dashed parameters. (like 'echo $arg0')
  • More code examples and documentation

About

Node.js library to help build awesome command line tools.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published