\href{http://travis-ci.org/nodeca/argparse}{\texttt{ }} \href{https://www.npmjs.org/package/argparse}{\texttt{ }}

CLI arguments parser for node.\+js. Javascript port of python\textquotesingle{}s \href{http://docs.python.org/dev/library/argparse.html}{\texttt{ argparse}} module (original version 3.\+2). That\textquotesingle{}s a full port, except some very rare options, recorded in issue tracker.

{\bfseries{NB. Difference with original.}}


\begin{DoxyItemize}
\item Method names changed to camel\+Case. See \href{http://nodeca.github.com/argparse/}{\texttt{ generated docs}}.
\item Use {\ttfamily default\+Value} instead of {\ttfamily default}.
\item Use {\ttfamily argparse.\+Const.\+REMAINDER} instead of {\ttfamily argparse.\+REMAINDER}, and similarly for constant values {\ttfamily OPTIONAL}, {\ttfamily ZERO\+\_\+\+OR\+\_\+\+MORE}, and {\ttfamily ONE\+\_\+\+OR\+\_\+\+MORE} (aliases for {\ttfamily nargs} values `'?\textquotesingle{}{\ttfamily ,}\textquotesingle{}$\ast$\textquotesingle{}{\ttfamily ,}\textquotesingle{}+\textquotesingle{}{\ttfamily , respectively), and }SUPPRESS\`{}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3133}{}\doxysection{Example}\label{md_sfcode_node_modules_argparse_README_autotoc_md3133}
test.\+js file\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\#!/usr/bin/env node}
\DoxyCodeLine{'use strict';}
\DoxyCodeLine{}
\DoxyCodeLine{var ArgumentParser = require('../lib/argparse').ArgumentParser;}
\DoxyCodeLine{var parser = new ArgumentParser(\{}
\DoxyCodeLine{  version: '0.0.1',}
\DoxyCodeLine{  addHelp:true,}
\DoxyCodeLine{  description: 'Argparse example'}
\DoxyCodeLine{\});}
\DoxyCodeLine{parser.addArgument(}
\DoxyCodeLine{  [ '-\/f', '-\/-\/foo' ],}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    help: 'foo bar'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{);}
\DoxyCodeLine{parser.addArgument(}
\DoxyCodeLine{  [ '-\/b', '-\/-\/bar' ],}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    help: 'bar foo'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{);}
\DoxyCodeLine{parser.addArgument(}
\DoxyCodeLine{  '-\/-\/baz',}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    help: 'baz bar'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{);}
\DoxyCodeLine{var args = parser.parseArgs();}
\DoxyCodeLine{console.dir(args); }

\end{DoxyCode}


Display help\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ ./test.js -\/h}
\DoxyCodeLine{usage: example.js [-\/h] [-\/v] [-\/f FOO] [-\/b BAR] [-\/-\/baz BAZ]}
\DoxyCodeLine{}
\DoxyCodeLine{Argparse example}
\DoxyCodeLine{}
\DoxyCodeLine{Optional arguments:}
\DoxyCodeLine{  -\/h, -\/-\/help         Show this help message and exit.}
\DoxyCodeLine{  -\/v, -\/-\/version      Show program's version number and exit.}
\DoxyCodeLine{  -\/f FOO, -\/-\/foo FOO  foo bar}
\DoxyCodeLine{  -\/b BAR, -\/-\/bar BAR  bar foo}
\DoxyCodeLine{  -\/-\/baz BAZ          baz bar }

\end{DoxyCode}


Parse arguments\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ ./test.js -\/f=3 -\/-\/bar=4 -\/-\/baz 5}
\DoxyCodeLine{\{ foo: '3', bar: '4', baz: '5' \} }

\end{DoxyCode}


More \href{https://github.com/nodeca/argparse/tree/master/examples}{\texttt{ examples}}.\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3134}{}\doxysection{Argument\+Parser objects}\label{md_sfcode_node_modules_argparse_README_autotoc_md3134}

\begin{DoxyCode}{0}
\DoxyCodeLine{new ArgumentParser(\{parameters hash\}); }

\end{DoxyCode}


Creates a new Argument\+Parser object.

{\bfseries{Supported params\+:}}


\begin{DoxyItemize}
\item {\ttfamily description} -\/ Text to display before the argument help.
\item {\ttfamily epilog} -\/ Text to display after the argument help.
\item {\ttfamily add\+Help} -\/ Add a -\/h/–help option to the parser. (default\+: true)
\item {\ttfamily argument\+Default} -\/ Set the global default value for arguments. (default\+: null)
\item {\ttfamily parents} -\/ A list of Argument\+Parser objects whose arguments should also be included.
\item {\ttfamily prefix\+Chars} -\/ The set of characters that prefix optional arguments. (default\+: ‘-\/‘)
\item {\ttfamily formatter\+Class} -\/ A class for customizing the help output.
\item {\ttfamily prog} -\/ The name of the program (default\+: {\ttfamily path.\+basename(process.\+argv\mbox{[}1\mbox{]})})
\item {\ttfamily usage} -\/ The string describing the program usage (default\+: generated)
\item {\ttfamily conflict\+Handler} -\/ Usually unnecessary, defines strategy for resolving conflicting optionals.
\end{DoxyItemize}

{\bfseries{Not supported yet}}


\begin{DoxyItemize}
\item {\ttfamily fromfile\+Prefix\+Chars} -\/ The set of characters that prefix files from which additional arguments should be read.
\end{DoxyItemize}

Details in \href{http://docs.python.org/dev/library/argparse.html\#argumentparser-objects}{\texttt{ original Argument\+Parser guide}}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3135}{}\doxysection{add\+Argument() method}\label{md_sfcode_node_modules_argparse_README_autotoc_md3135}

\begin{DoxyCode}{0}
\DoxyCodeLine{ArgumentParser.addArgument(name or flag or [name] or [flags...], \{options\}) }

\end{DoxyCode}


Defines how a single command-\/line argument should be parsed.


\begin{DoxyItemize}
\item {\ttfamily name or flag or \mbox{[}name\mbox{]} or \mbox{[}flags...\mbox{]}} -\/ Either a positional name (e.\+g., `\textquotesingle{}foo'{\ttfamily ), a single option (e.\+g.,}\textquotesingle{}-\/f\textquotesingle{}{\ttfamily or}\textquotesingle{}--foo\textquotesingle{}{\ttfamily ), an array of a single positional name (e.\+g.,}\mbox{[}\textquotesingle{}foo\textquotesingle{}\mbox{]}{\ttfamily ), or an array of options (e.\+g.,}\mbox{[}\textquotesingle{}-\/f\textquotesingle{}, \textquotesingle{}--foo\textquotesingle{}\mbox{]}\`{}).
\end{DoxyItemize}

Options\+:


\begin{DoxyItemize}
\item {\ttfamily action} -\/ The basic type of action to be taken when this argument is encountered at the command line.
\item {\ttfamily nargs}-\/ The number of command-\/line arguments that should be consumed.
\item {\ttfamily constant} -\/ A constant value required by some action and nargs selections.
\item {\ttfamily default\+Value} -\/ The value produced if the argument is absent from the command line.
\item {\ttfamily type} -\/ The type to which the command-\/line argument should be converted.
\item {\ttfamily choices} -\/ A container of the allowable values for the argument.
\item {\ttfamily required} -\/ Whether or not the command-\/line option may be omitted (optionals only).
\item {\ttfamily help} -\/ A brief description of what the argument does.
\item {\ttfamily metavar} -\/ A name for the argument in usage messages.
\item {\ttfamily dest} -\/ The name of the attribute to be added to the object returned by parse\+Args().
\end{DoxyItemize}

Details in \href{http://docs.python.org/dev/library/argparse.html\#the-add-argument-method}{\texttt{ original add\+\_\+argument guide}}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3136}{}\doxysection{Action (some details)}\label{md_sfcode_node_modules_argparse_README_autotoc_md3136}
Argument\+Parser objects associate command-\/line arguments with actions. These actions can do just about anything with the command-\/line arguments associated with them, though most actions simply add an attribute to the object returned by parse\+Args(). The action keyword argument specifies how the command-\/line arguments should be handled. The supported actions are\+:


\begin{DoxyItemize}
\item {\ttfamily store} -\/ Just stores the argument’s value. This is the default action.
\item {\ttfamily store\+Const} -\/ Stores value, specified by the const keyword argument. (Note that the const keyword argument defaults to the rather unhelpful None.) The \textquotesingle{}store\+Const\textquotesingle{} action is most commonly used with optional arguments, that specify some sort of flag.
\item {\ttfamily store\+True} and {\ttfamily store\+False} -\/ Stores values True and False respectively. These are special cases of \textquotesingle{}store\+Const\textquotesingle{}.
\item {\ttfamily append} -\/ Stores a list, and appends each argument value to the list. This is useful to allow an option to be specified multiple times.
\item {\ttfamily append\+Const} -\/ Stores a list, and appends value, specified by the const keyword argument to the list. (Note, that the const keyword argument defaults is None.) The \textquotesingle{}append\+Const\textquotesingle{} action is typically used when multiple arguments need to store constants to the same list.
\item {\ttfamily count} -\/ Counts the number of times a keyword argument occurs. For example, used for increasing verbosity levels.
\item {\ttfamily help} -\/ Prints a complete help message for all the options in the current parser and then exits. By default a help action is automatically added to the parser. See Argument\+Parser for details of how the output is created.
\item {\ttfamily version} -\/ Prints version information and exit. Expects a {\ttfamily version=} keyword argument in the add\+Argument() call.
\end{DoxyItemize}

Details in \href{http://docs.python.org/dev/library/argparse.html\#action}{\texttt{ original action guide}}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3137}{}\doxysection{Sub-\/commands}\label{md_sfcode_node_modules_argparse_README_autotoc_md3137}
Argument\+Parser.\+add\+Subparsers()

Many programs split their functionality into a number of sub-\/commands, for example, the svn program can invoke sub-\/commands like {\ttfamily svn checkout}, {\ttfamily svn update}, and {\ttfamily svn commit}. Splitting up functionality this way can be a particularly good idea when a program performs several different functions which require different kinds of command-\/line arguments. {\ttfamily Argument\+Parser} supports creation of such sub-\/commands with {\ttfamily add\+Subparsers()} method. The {\ttfamily add\+Subparsers()} method is normally called with no arguments and returns an special action object. This object has a single method {\ttfamily add\+Parser()}, which takes a command name and any {\ttfamily Argument\+Parser} constructor arguments, and returns an {\ttfamily Argument\+Parser} object that can be modified as usual.

Example\+:

sub\+\_\+commands.\+js 
\begin{DoxyCode}{0}
\DoxyCodeLine{\#!/usr/bin/env node}
\DoxyCodeLine{'use strict';}
\DoxyCodeLine{}
\DoxyCodeLine{var ArgumentParser = require('../lib/argparse').ArgumentParser;}
\DoxyCodeLine{var parser = new ArgumentParser(\{}
\DoxyCodeLine{  version: '0.0.1',}
\DoxyCodeLine{  addHelp:true,}
\DoxyCodeLine{  description: 'Argparse examples: sub-\/commands',}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{var subparsers = parser.addSubparsers(\{}
\DoxyCodeLine{  title:'subcommands',}
\DoxyCodeLine{  dest:"{}subcommand\_name"{}}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{var bar = subparsers.addParser('c1', \{addHelp:true\});}
\DoxyCodeLine{bar.addArgument(}
\DoxyCodeLine{  [ '-\/f', '-\/-\/foo' ],}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    action: 'store',}
\DoxyCodeLine{    help: 'foo3 bar3'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{);}
\DoxyCodeLine{var bar = subparsers.addParser(}
\DoxyCodeLine{  'c2',}
\DoxyCodeLine{  \{aliases:['co'], addHelp:true\}}
\DoxyCodeLine{);}
\DoxyCodeLine{bar.addArgument(}
\DoxyCodeLine{  [ '-\/b', '-\/-\/bar' ],}
\DoxyCodeLine{  \{}
\DoxyCodeLine{    action: 'store',}
\DoxyCodeLine{    type: 'int',}
\DoxyCodeLine{    help: 'foo3 bar3'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{);}
\DoxyCodeLine{}
\DoxyCodeLine{var args = parser.parseArgs();}
\DoxyCodeLine{console.dir(args);}

\end{DoxyCode}


Details in \href{http://docs.python.org/dev/library/argparse.html\#sub-commands}{\texttt{ original sub-\/commands guide}}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3138}{}\doxysection{Contributors}\label{md_sfcode_node_modules_argparse_README_autotoc_md3138}

\begin{DoxyItemize}
\item \href{https://github.com/shkuropat}{\texttt{ Eugene Shkuropat}}
\item \href{https://github.com/hpaulj}{\texttt{ Paul Jacobson}}
\end{DoxyItemize}

\href{https://github.com/nodeca/argparse/graphs/contributors}{\texttt{ others}}\hypertarget{md_sfcode_node_modules_argparse_README_autotoc_md3139}{}\doxysection{License}\label{md_sfcode_node_modules_argparse_README_autotoc_md3139}
Copyright (c) 2012 \href{https://github.com/puzrin}{\texttt{ Vitaly Puzrin}}. Released under the MIT license. See \href{https://github.com/nodeca/argparse/blob/master/LICENSE}{\texttt{ LICENSE}} for details. 