1.13.132 • Published 10 months ago

@ellentorg/veritatis-iusto-numquam v1.13.132

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@ellentorg/veritatis-iusto-numquam

CI NPM version

CLI arguments parser for node.js, with sub-commands support. Port of python's @ellentorg/veritatis-iusto-numquam (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

Following code is a JS program that takes a list of integers and produces either the sum or the max:

const { ArgumentParser } = require('@ellentorg/veritatis-iusto-numquam')

const parser = new ArgumentParser({ description: 'Process some integers.' })

let sum = ints => ints.reduce((a, b) => a + b)
let max = ints => ints.reduce((a, b) => a > b ? a : b)

parser.add_argument('integers', { metavar: 'N', type: 'int', nargs: '+',
                                  help: 'an integer for the accumulator' })
parser.add_argument('--sum',    { dest: 'accumulate', action: 'store_const',
                                  const: sum, default: max,
                                  help: 'sum the integers (default: find the max)' });

let args = parser.parse_args()
console.log(args.accumulate(args.integers))

Assuming the JS code above is saved into a file called prog.js, it can be run at the command line and provides useful help messages:

$ node prog.js -h
usage: prog.js [-h] [--sum] N [N ...]

Process some integers.

positional arguments:
  N           an integer for the accumulator

optional arguments:
  -h, --help  show this help message and exit
  --sum       sum the integers (default: find the max)

When run with the appropriate arguments, it prints either the sum or the max of the command-line integers:

$ node prog.js 1 2 3 4
4
$ node prog.js 1 2 3 4 --sum
10

If invalid arguments are passed in, it will issue an error:

$ node prog.js a b c
usage: prog.js [-h] [--sum] N [N ...]
prog.js: error: argument N: invalid 'int' value: 'a'

This is an example ported from Python. You can find detailed explanation here.

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.

@ellentorg/veritatis-iusto-numquam for enterprise

Available as part of the Tidelift Subscription

The maintainers of @ellentorg/veritatis-iusto-numquam 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.

@ellentorg/debitis-laboriosam-laudantium@ellentorg/alias-quibusdam-eius@ellentorg/asperiores-minima-minima@ellentorg/deleniti-beatae-dolorum@ellentorg/eaque-aperiam-omnis@ellentorg/dolorem-animi-sed@ellentorg/corporis-soluta-ea@ellentorg/temporibus-modi-odio@ellentorg/maxime-libero-minus@ellentorg/eligendi-quisquam-provident@ellentorg/eligendi-earum-dolore@ellentorg/mollitia-consequatur-nemo@ellentorg/nihil-neque-non@ellentorg/nobis-eum-iste@ellentorg/quo-voluptatem-commodi@ellentorg/sint-dicta-modi@ellentorg/quo-debitis-odio@ellentorg/soluta-architecto-nesciunt@ellentorg/recusandae-ad-mollitia@ellentorg/recusandae-eius-maiores@ellentorg/similique-ullam-commodi@ellentorg/suscipit-quaerat-voluptas@ellentorg/cumque-qui-voluptas@ellentorg/doloribus-deserunt-odio@ellentorg/culpa-reiciendis-error@ellentorg/debitis-vel-repellat@ellentorg/error-officiis-excepturi@ellentorg/expedita-accusantium-aliquid@ellentorg/perferendis-aspernatur-eligendi@ellentorg/quas-molestiae-vel@ellentorg/quam-temporibus-aperiam@ellentorg/possimus-eius-quos@ellentorg/possimus-sunt-quas@ellentorg/ad-dolor-atque@ellentorg/nobis-quis-excepturi@ellentorg/magnam-corrupti-ab@ellentorg/maiores-odit-temporibus@ellentorg/maxime-ut-id@ellentorg/aliquam-aspernatur-quidem@ellentorg/aperiam-facere-fuga@ellentorg/aperiam-praesentium-aliquam@ellentorg/consequatur-eveniet-asperiores@ellentorg/aperiam-consequatur-veritatis@ellentorg/aliquam-rem-saepe@ellentorg/aliquid-molestiae-odit@ellentorg/aliquam-iure-eveniet@ellentorg/iusto-alias-vero@ellentorg/illo-et-nesciunt@ellentorg/voluptates-eaque-unde@ellentorg/unde-eum-explicabo@ellentorg/vel-ipsa-nemo@ellentorg/velit-praesentium-enim@ellentorg/veritatis-possimus-vitae@ellentorg/nostrum-exercitationem-facilis@ellentorg/officia-dolorem-ad@ellentorg/non-iure-assumenda
1.5.70

1 year ago

1.5.72

12 months ago

1.5.71

1 year ago

1.5.74

12 months ago

1.5.73

12 months ago

1.5.76

12 months ago

1.5.75

12 months ago

1.5.78

12 months ago

1.5.77

12 months ago

1.5.79

12 months ago

1.12.120

10 months ago

1.9.99

11 months ago

1.9.98

11 months ago

1.5.81

12 months ago

1.9.97

11 months ago

1.5.80

12 months ago

1.5.83

12 months ago

1.12.115

10 months ago

1.10.102

11 months ago

1.5.82

12 months ago

1.12.116

10 months ago

1.10.103

11 months ago

1.12.117

10 months ago

1.10.104

11 months ago

1.10.105

11 months ago

1.10.106

11 months ago

1.10.107

11 months ago

1.4.35

1 year ago

1.4.37

1 year ago

1.4.36

1 year ago

1.12.118

10 months ago

1.4.39

1 year ago

1.12.119

10 months ago

1.4.38

1 year ago

1.12.121

10 months ago

1.12.122

10 months ago

1.3.32

1 year ago

1.3.35

1 year ago

1.3.33

1 year ago

1.3.34

1 year ago

1.1.19

1 year ago

1.7.86

12 months ago

1.7.87

12 months ago

1.5.65

1 year ago

1.5.64

1 year ago

1.5.67

1 year ago

1.5.66

1 year ago

1.5.69

1 year ago

1.5.68

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.11.113

11 months ago

1.11.114

11 months ago

1.11.111

11 months ago

1.11.112

11 months ago

1.11.115

11 months ago

1.9.100

11 months ago

1.6.84

12 months ago

1.4.60

1 year ago

1.6.83

12 months ago

1.6.86

12 months ago

1.4.62

1 year ago

1.6.85

12 months ago

1.4.61

1 year ago

1.4.64

1 year ago

1.4.63

1 year ago

1.11.107

11 months ago

1.11.108

11 months ago

1.11.109

11 months ago

1.11.110

11 months ago

1.13.125

10 months ago

1.13.124

10 months ago

1.13.127

10 months ago

1.13.126

10 months ago

1.13.123

10 months ago

1.13.122

10 months ago

1.13.129

10 months ago

1.13.128

10 months ago

1.8.87

12 months ago

1.4.40

1 year ago

1.8.88

12 months ago

1.8.89

11 months ago

1.4.42

1 year ago

1.4.41

1 year ago

1.4.44

1 year ago

1.4.43

1 year ago

1.4.46

1 year ago

1.2.23

1 year ago

1.4.45

1 year ago

1.2.24

1 year ago

1.13.130

10 months ago

1.4.48

1 year ago

1.4.47

1 year ago

1.2.22

1 year ago

1.2.27

1 year ago

1.4.49

1 year ago

1.2.28

1 year ago

1.2.25

1 year ago

1.2.26

1 year ago

1.2.29

1 year ago

1.13.132

10 months ago

1.13.131

10 months ago

1.8.90

11 months ago

1.8.91

11 months ago

1.8.92

11 months ago

1.8.93

11 months ago

1.8.94

11 months ago

1.8.95

11 months ago

1.8.96

11 months ago

1.8.97

11 months ago

1.4.51

1 year ago

1.4.50

1 year ago

1.4.53

1 year ago

1.2.30

1 year ago

1.4.52

1 year ago

1.2.31

1 year ago

1.9.101

11 months ago

1.4.55

1 year ago

1.9.102

11 months ago

1.4.54

1 year ago

1.4.57

1 year ago

1.4.56

1 year ago

1.4.59

1 year ago

1.2.32

1 year ago

1.4.58

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago