Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

argparse

Package Overview
Dependencies
0
Maintainers
1
Versions
30
Issues
File Explorer

Advanced tools

argparse

CLI arguments parser. Native port of python's argparse.

    2.0.1latest

Version published
Maintainers
1
Weekly downloads
55,014,185
increased by4.14%

Weekly downloads

Changelog

Source

[2.0.1] - 2020-08-29

Fixed

  • Fix issue with process.argv when used with interpreters (coffee, ts-node, etc.), #150.

Readme

Source

argparse

Build Status NPM version

CLI arguments parser for node.js, with sub-commands support. Port of python's argparse (version 3.9.0).

Difference with original.

  • JS has no keyword arguments support.
    • Pass options instead: new ArgumentParser({ description: 'example', add_help: true }).
  • JS has no python's types int, float, ...
    • Use string-typed names: .add_argument('-b', { type: 'int', help: 'help' }).
  • %r format specifier uses require('util').inspect().

More details in doc.

Example

test.js file:

#!/usr/bin/env node 'use strict'; const { ArgumentParser } = require('argparse'); const { version } = require('./package.json'); const parser = new ArgumentParser({ description: 'Argparse example' }); parser.add_argument('-v', '--version', { action: 'version', version }); parser.add_argument('-f', '--foo', { help: 'foo bar' }); parser.add_argument('-b', '--bar', { help: 'bar foo' }); parser.add_argument('--baz', { help: 'baz bar' }); console.dir(parser.parse_args());

Display help:

$ ./test.js -h usage: test.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ] Argparse example optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit -f FOO, --foo FOO foo bar -b BAR, --bar BAR bar foo --baz BAZ baz bar

Parse arguments:

$ ./test.js -f=3 --bar=4 --baz 5 { foo: '3', bar: '4', baz: '5' }

API docs

Since this is a port with minimal divergence, there's no separate documentation. Use original one instead, with notes about difference.

  1. Original doc.
  2. Original tutorial.
  3. Difference with python.

argparse for enterprise

Available as part of the Tidelift Subscription

The maintainers of argparse and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Keywords

FAQs

What is argparse?

CLI arguments parser. Native port of python's argparse.

Is argparse popular?

The npm package argparse receives a total of 46,302,370 weekly downloads. As such, argparse popularity was classified as popular.

Is argparse well maintained?

We found that argparse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 28 Aug 2020

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc