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

simple-argparse

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-argparse

Simple Argument parser for Command-line Applications

  • 0.0.0-alpha.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
2
Weekly downloads
 
Created
Source

simple-argparse

Simple Argument parser for Command-line Applications

module information

Build Status

AspectDetail
Version0.0.0-alpha.1.0
Node0.11, 0.10, 0.8, 0.6
Last Updated13th Oct, 2014

installation

$ npm install simple-argparse

basic usage

Sample.js:

require("simple-argparse")
  .description("Application Description")
  .version("0.3.0")
  .option("start", "starts application", startFunc)
  .epilog("See License at http://opensource.org/licenses/MIT")
  .parse()

function startFunc(host, port) {
  app.listen(port, host);
}

Sample Output:

$ node Sample.js
Application Description

 help     show this help information
 start    starts application
 version  show version information

See License at http://opensource.org/licenses/MIT

The module exports a new Parser, that can be used immediately. If you wish to create more Parsers, you could:

var Parser = require("simple-argparse").Parser;
var myParser = new myParser();

While instantiating a parser, an output function may be registered with the parser other than the default console.log

var myOtherParser = new myParser(function(output) {
  socket.emit("commandComplete", output);
});

A Parser has these methods:

  1. parser#description([name:String,] description:String)
  • name:(Optional) preferably refers to the name of your Application

  • description: provides a description of your Application

  • parser#version(version:String)

  • version: provides version information of your Application

  • defaults to "0.0.0"

  • parser#option(command:String, description:String [, optionFunction:Function])

  • command:

    • a string that will be typed by user to fire command
    • any spaces will be replaced by hyphens
  • description: information regarding this command

  • optionFunction:(Optional)

    • Function called when the command is entered by user
    • Is passed ALL arguments following the command as strings
    • For example, in the sample script above:
      • $ node Sample.js start localhost 9999
      • localhost and 9999 are passed to the option function for start i.e. startFunc
    • Leaving out this function, makes the parser ignore this option
    • That may be useful for commands not yet implemented
  • parser#epilog(epilog:String)

  • epilog: a string that will appear at the bottom of help information

  • parser#parse([arguments:String])

  • arguments:(Optional)

    • a string representing commands as typed in command-line
    • if left out, process.argv will be used instead
  • parser#showHelp()

    • shows the help information
    • is done by passing all the necessary data as string to the registered output function
  • parser#showVersion()

    • similar to parser#showHelp() but only supplies version information

license

Copyright (c) 2014 Forfuture LLC

Simple-argparse and its source code is issued under the MIT license.

Keywords

FAQs

Package last updated on 14 Oct 2014

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