Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arghandle

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arghandle

library to parse commandline-args and options.

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

argHandle Build Status

Library to parse commandline-args and options.

Usage

##Install

npm install arghandle

##Implementation Require this module into your project

var arghandle = require('arghandle'),
    handle = new arghandle();

    handle.process();

You can test this by running

node yourscript.js --help

This is a reserved keyword. This will show all the handelers that have been defined

###Defining custom argument handlers A handler object should be designed like the following:

{
    keys: ['--port', '-P'], // e.g. node script.js [--port|-P] 8080
    method: function (self) {
        console.log(self.getNext()); // 8080
    },
    description: 'Set application listning port'
}

Their are three methods to append your argument handlers. ####Initially declaring the options

var handle = new arghandle({
    // This defines the start point for arguments to get processed
    startIndex: 5,
    // This defines the custom argument handlers
    definedArgs: [
        {
            keys: ['--yes-debug', '-D'],
            method: function (self) {
                appConfig.debug = true;
            },
            description: 'Set application to debug'
        },
        {
            keys: ['--port', '-P'],
            method: function (self) {
                appConfig.port = self.getNext();
            },
            description: 'Set application listning port'
        }
    ],
    // This defines arguments passed by the command line
    argv: process.argv
}); 

####Concating an array of handlers

var appConfig = {
    debug: false,
    port: 8080,
    hostname: 'localhost'
};

handle.concat([
    {
        keys: ['--debug', '-D'],
        method: function (self) {
            appConfig.debug = true;
        },
        description: 'Set application to debug'
    },
    {
        keys: ['--port', '-P'],
        method: function (self) {
            appConfig.port = self.getNext();
        },
        description: 'Set application listning port'
    }
]);

####Appending a single handler

handle.push({
    keys: ['--hostname', '-H'],
    method: function (self) {
        appConfig.hostname = self.getNext();
    },
    description: 'Set application listning hostname'
});

####Defining the start position for arguments This is declared in the initial method. This is done as follows...

var handle = new arghandle({
    startIndex: 2
});

###Processing the arguments This is done by calling the method as follows...

handle.process(process.argv); // if argv is not declared in the initial method
handle.process(); // if argv was included in the initial method

This will return false if an undefined argument is sent

Keywords

FAQs

Package last updated on 18 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc