npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

options-cli

v1.5.5

Published

Nodejs Command-line option parser.

Readme

Options-cli

Annother Nodejs Command-line option parser.

USAGE

    var options = require("options-cli")(schema,option);

SCHEMA


Expects the "schema" array with options definitions and produces the "options" object and the "arguments" array, which will contain all non-option arguments encountered (including the script name and such).

Syntax:

[«short», «long», «attributes», «brief», [«callback»],[«error»]]

Attributes:

! - option is mandatory;
: - option expects a parameter;
+ - option may be specified multiple times (repeatable).
val1,val2,val3,val4,...valN - list of possible value

Notes:

- Parser is case-sensitive.
- The '-?|--help' option is provided implicitly.
- Parsed options are placed as fields in the "options" object.
- Non-option arguments are placed in the "arguments" array.
- Options and their parameters must be separated by space.
- Either one of «short» or «long» must always be provided.
- The «callback» function is optional.
- Cumulated short options are supported (i.e. '-tv').
- If an error occurs, the process is halted and the help is shown.
- Repeatable options will be cumulated into arrays.
- The parser does *not* test for duplicate option definitions.
   var schema = [
           ['f', 'file',    '!:', "Some file we really need.","Error message" ],
           ['t', 'test',    '!',  'I am needed also.'],
           ['',  'log',   "+!info,debug,warning,error",  'log info level'],
           ['l',  'level',   ':',  'Debug level (values 0-4).',function(d){
               d = parseInt(d+0);
                   return isNaN(d) || Math.abs(d) <0 || Math.abs(d) >4 ;
           },"Must be a number bettewen 0-4"],
           ['p',  'port',   ':',  'Port.',function(d){
               d = parseInt(d+0);
               if(isNaN(d))
                   return "Error bad type must a number";
               else if(d<1024)
                   return "Never run in root mode";
           }],
           ['d', '',        '+',   'Enable debug mode.'],
           ['v', 'verbose', '+',  'Verbosity levels (can be used repeatedly).'],
   ];

OPTIONS


Option is a object with this properties :

- onArgs : (default: new Function) [callback]  Valid arguments ,
- exit : (default: true) [Boolean] True : print error and exit; False : return error object,
- args : (default: '--') [String] label for argument value,
- script : (default: "«script»") [String] Name of script,
- strict : (default false) [Boolean] Show error on unknow argument
- help : (default: "") [String] text of extra help ,
- desc : (default: "") [String] text of description of script,
- values : (default: "«values»") [String] text of value argument in help

    
var options = {      
            onArgs : function(cfg){
                    if(!cfg) return "Config file is not defined;";
                    if(!path.existsSync(cfg.app(__dirname))){
                            return "Config file not exist;";
                    }
            },
            script : "myapps",
            values : '/path/to/conf/file',
            desc : "MyApps is"
    }    

REAL EXEMPLE

filename script.js

var options = require("options-cli")([
		['p', 'port', ':', "Port d'ecoute du serveur." ],
		['h', 'host', ':', "Port d'ecoute du serveur." ],
		['c', 'conf',    ':', 'Fichier de configuration.'],
		['l', 'log' , ':', "Fichier de log"],
		['L', 'error' , ':', "Fichier de log des erreurs"],
		['d','',"+",'Active le debug'],
		['v', 'version', '',  "Obtention des version",function(){
			console.log(process.versions);
			process.exit(0); // 0 for no error
		}]
	],{
		script : require("path").basename(process.argv[0]),
		desc :
"     _   _   _   _____   _____        _____   _____   _____         _____   _   _   __   _\n"+ 
"    | | | | | | /  ___/ |_   _|      |  ___| /  _  \\ |  _  \\       |  ___| | | | | |  \\ | |\n"+ 
"    | | | | | | | |___    | |        | |__   | | | | | |_| |       | |__   | | | | |   \\| |\n"+ 
" _  | | | | | | \\___  \\   | |        |  __|  | | | | |  _  /       |  __|  | | | | | |\\   |\n"+ 
"| |_| | | |_| |  ___| |   | |        | |     | |_| | | | \\ \\       | |     | |_| | | | \\  |\n"+ 
"\\_____/ \\_____/ /_____/   |_|        |_|     \\_____/ |_|  \\_\\      |_|     \\_____/ |_|  \\_|\n"
// JUST FOR FUN
	});

const http = require('http');
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(options.port || 1337, options.host || '127.0.0.1', () => {
  console.log(`Server running at http://${options.host}:${options.port}/`);
}); 

execution $ script.js -p 80 -h 192.168.1.1

Copyright 2011 Badlee Oshimin. All rights reserved. Released as Public Domain.