1.13.132 • Published 11 months ago

@ellentorg/veritatis-iusto-numquam v1.13.132

Weekly downloads
-
License
MIT
Repository
github
Last release
11 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

1 year ago

1.5.71

1 year ago

1.5.74

1 year ago

1.5.73

1 year ago

1.5.76

1 year ago

1.5.75

1 year ago

1.5.78

1 year ago

1.5.77

1 year ago

1.5.79

1 year ago

1.12.120

12 months ago

1.9.99

1 year ago

1.9.98

1 year ago

1.5.81

1 year ago

1.9.97

1 year ago

1.5.80

1 year ago

1.5.83

1 year ago

1.12.115

12 months ago

1.10.102

1 year ago

1.5.82

1 year ago

1.12.116

12 months ago

1.10.103

1 year ago

1.12.117

12 months ago

1.10.104

1 year ago

1.10.105

1 year ago

1.10.106

1 year ago

1.10.107

1 year ago

1.4.35

1 year ago

1.4.37

1 year ago

1.4.36

1 year ago

1.12.118

12 months ago

1.4.39

1 year ago

1.12.119

12 months ago

1.4.38

1 year ago

1.12.121

12 months ago

1.12.122

12 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

1 year ago

1.7.87

1 year 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

1 year ago

1.11.114

12 months ago

1.11.111

1 year ago

1.11.112

1 year ago

1.11.115

12 months ago

1.9.100

1 year ago

1.6.84

1 year ago

1.4.60

1 year ago

1.6.83

1 year ago

1.6.86

1 year ago

1.4.62

1 year ago

1.6.85

1 year ago

1.4.61

1 year ago

1.4.64

1 year ago

1.4.63

1 year ago

1.11.107

1 year ago

1.11.108

1 year ago

1.11.109

1 year ago

1.11.110

1 year ago

1.13.125

12 months ago

1.13.124

12 months ago

1.13.127

12 months ago

1.13.126

12 months ago

1.13.123

12 months ago

1.13.122

12 months ago

1.13.129

12 months ago

1.13.128

12 months ago

1.8.87

1 year ago

1.4.40

1 year ago

1.8.88

1 year ago

1.8.89

1 year 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

12 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

11 months ago

1.13.131

12 months ago

1.8.90

1 year ago

1.8.91

1 year ago

1.8.92

1 year ago

1.8.93

1 year ago

1.8.94

1 year ago

1.8.95

1 year ago

1.8.96

1 year ago

1.8.97

1 year 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

1 year ago

1.4.55

1 year ago

1.9.102

1 year 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