Coder Social home page Coder Social logo

trollopjs's Introduction

trollopjs

Trollop is a command line option parser for Ruby.

trollopjs is a port of that to work with the Node javascript library.

Almost everything is working except for the formatting of the help message. Read about the differences below.

DESCRIPTION

trollopjs is a commandline option parser for Node that just gets out of your way. One line of code per option is all you need to write. For that, you get a nice automatically-generated help page, robust option parsing, command subcompletion, and sensible defaults for everything you don't specify.

DOCUMENTATION/QUICK START

I have no documentation. But if you are curious you can consult the Ruby docs for the original Trollop:

http://trollop.rubyforge.org/

Or you can checkout the files in the examples dir.

QUICK EXAMPLE

var trollopjs = require('trollopjs');

var opts = trollopjs.options(function() {
  this.opt('monkey', "Use monkey mode");                       // a flag --monkey, defaulting to false
  this.opt('goat', "Use goat mode", {dflt: true});             // a flag --goat, defaulting to true
  this.opt('num_limbs', "Number of limbs", {dflt: 4});         // an integer --num-limbs <i>, defaulting to 4
  this.opt('num_thumbs', "Number of thumbs", {type: 'int'});   // an integer --num-thumbs <i>, defaulting to nil
});

var sys = require('sys');
sys.puts(sys.inspect(opts));
/* prints:
{
 "monkey": false,
 "goat": true,
 "num_limbs": 4,
 "help": false
}
*/

INSTALLING/RUNNING

Checkout out the code and make sure it is in your node path.

The easiest way to get it running is to check it out into ~/.node_libraries:

mkdir -p ~/.node_libraries
git clone git://github.com/bentomas/trollopjs.git ~/.node_libraries/trollopjs

Run a file with the following command:

node filename.js

Pass it parameters:

node filename.js --monkey

The node command has a tendency to steal 'help' and 'version' arguments, so if you follow it up with -- you won't run into any problems:

node -- filename.js --help

FEATURES/PROBLEMS

(taken from the Trollop README)

  • Dirt-simple usage.
  • Sensible defaults. No tweaking necessary, much tweaking possible.
  • Support for long options, short options, short option bundling, and automatic type validation and conversion.
  • Support for subcommands.
  • Automatic help message generation, wrapped to current screen width.
  • Lots of unit tests.

DIFFERENCES FROM THE RUBY TROLLOP

The Ruby Trollop has an IO type. At this time there isn't a good mapping for that in Node, so I removed it.

default is a keyword in javascript, so the option has been renamed dflt.

I haven't implemented the Trollop::die function.

LICENSE

trollopjs is distributed under the same terms as Trollop:

Copyright (c) 2008--2009 William Morgan. Trollop is distributed under the same terms as Ruby.

ABOUT THE RUBY TROLLOP

Trollop is origonally by William Morgan (http://masanjin.net/)

Main page: http://trollop.rubyforge.org

Release announcements and comments: http://all-thing.net/label/trollop

trollopjs's People

Contributors

ncb000gt avatar

Stargazers

Dinesh Kr. Choudhary avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

dineshkummarc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.