argparse

WebJar for argparse

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.bowergithub.nodeca
Идентификатор

Идентификатор

argparse
Последняя версия

Последняя версия

1.0.10
Дата

Дата

Тип

Тип

jar
Описание

Описание

argparse
WebJar for argparse
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/nodeca/argparse

Скачать argparse

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.bowergithub.nodeca/argparse/ -->
<dependency>
    <groupId>org.webjars.bowergithub.nodeca</groupId>
    <artifactId>argparse</artifactId>
    <version>1.0.10</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bowergithub.nodeca/argparse/
implementation 'org.webjars.bowergithub.nodeca:argparse:1.0.10'
// https://jarcasting.com/artifacts/org.webjars.bowergithub.nodeca/argparse/
implementation ("org.webjars.bowergithub.nodeca:argparse:1.0.10")
'org.webjars.bowergithub.nodeca:argparse:jar:1.0.10'
<dependency org="org.webjars.bowergithub.nodeca" name="argparse" rev="1.0.10">
  <artifact name="argparse" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bowergithub.nodeca', module='argparse', version='1.0.10')
)
libraryDependencies += "org.webjars.bowergithub.nodeca" % "argparse" % "1.0.10"
[org.webjars.bowergithub.nodeca/argparse "1.0.10"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.bowergithub.alexei : sprintf.js jar [1.0.2,1.1)

Модули Проекта

Данный проект не имеет модулей.

argparse

CI 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');

// Formatter with support of `\n` in Help texts.
class HelpFormatter extends ArgumentParser.RawDescriptionHelpFormatter {
  // executes parent _split_lines for each line of the help, then flattens the result
  _split_lines(text, width) {
    return [].concat(...text.split('\n').map(line => super._split_lines(line, width)));
  }
}

const parser = new ArgumentParser({
  description: 'Argparse example',
  add_help: true,
  formatter_class: HelpFormatter
});

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.

org.webjars.bowergithub.nodeca

Nodeca

rcopen.com sources and node.js libraries

Версии библиотеки

Версия
1.0.10