1.0.5 • Published 6 days ago

@teamteanpm2024/vel-consequatur-totam v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

@teamteanpm2024/vel-consequatur-totam

CI NPM version

CLI arguments parser for node.js, with sub-commands support. Port of python's @teamteanpm2024/vel-consequatur-totam (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('@teamteanpm2024/vel-consequatur-totam')

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.

@teamteanpm2024/vel-consequatur-totam for enterprise

Available as part of the Tidelift Subscription

The maintainers of @teamteanpm2024/vel-consequatur-totam 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.

WebSocketsidleJSONkinesisjsonschemaUnderscorescheme-validationboundtrimRighttelephoneiestreamtslibmatchAllreal-timewaitkoreancloudtrailagentstylesharmonyminimallesspromisesargparseencryptionform-validationpostcssformattingprefixclassnamesvalidator3ds3__proto__bundlingnodejsextendES2023browserslistwatchFileomitpoint-freewatchingrm -frfunctionalArray.prototype.flatMapbyteOffsetiterationsharedarraybufferestreeStyleSheetmixinshas-ownupjwtec2popmotionpropertygradients css3ESnextredacttypanionclassnameFunction.prototype.namequerybeanstalkconsoleclass-validatorparsedescriptionloggingindicatorutilprocessoutputshimemitHyBies2017byteECMAScript 2016StreamsconnectSymbolMicrosoftObject.definePropertyeventEmittermkdirincludesrfc4122vpcparsingvalidationtextObject.entriesflattenArray.prototype.flathasinterrupts.envspringregexpimmutablevalidatecss-in-jses2018rmwordwraptacitgroupBycallcreateCSSguidES2018io-tsformsjoidebugpreserve-symlinkstapespinnerswgetprotocol-bufferstrimLeftcolumnpersistentstructuredClonehttpsPushhttppostcss-pluginconstnoperatelimitfixed-widthmapreducepathfseventsdeepcopyflatbootstrap cssECMAScript 2017optionenderawspositivecompile lesscallboundeverycharactersprivate datapicomatchECMAScript 2021datachineseimportexportshrinkwrapArray.prototype.flattenenumerableArray.prototype.filterjsdiffphoneclimapRFC-6455macostoStringTagpropiamArray.prototype.includesinputmime-dbentriesECMAScript 2019momentcurlcryptotoolssearchsyntaxfetchFloat32Arraycachecolorsinspectwebpackage.jsonlockfileconfigdom-testing-librarystoragegatewayelbdrageast-asian-widthdataviewsymlinkinternal0testingecmascriptirqcorsutilitytoSortedfileprototypeObject.isinstyled-componentscharacterTypeBoxviewArrayBuffer.prototype.slicearktypeeslintsharedqueuechaicodessuperagentrmdirlazyInt16ArraywatchECMAScript 2022BigInt64Arraytc39onceECMAScript 6statelessUint8ClampedArraymonorepoisConcatSpreadabletostringtagterminalreact-hookslanguagelinkendpointmergedotenvsettingsfindWeakSetcall-boundenvlimitconcatsortedhandlersconcatMapreact-hook-formwritablebreakRegExp#flagsReactiveExtensionsbannerInt8Arraybundlercore-jsbuffersmatchesregulargestures$.extendhashUint8Arraysymbolsdeep-cloneresolveargumentemrsanitizationcommand-linedeterministicpurespecgradients csscompareratedayjscss nestingtraverseinternal slotlruwarningES2016jasmineworkflowshellstatusfastcloneawesomesauceschemaECMAScript 3visualObject.fromEntriesserializationdatetypesafekeyslinttoobjecthigher-orderjapanesefromkeyes2015autoprefixerbootstrap lessaccessibilitynumberBigUint64Arraybrowserreact-testing-librarysesES2021eventDispatcheres7busysignalscommandimmertouchswfperformant256mrupreprocessorasciii18nESreadablemiddlewarepyyamlstringfunctionssigtermstylingrandomparentssetterstreams2regular expressionsassignroute53cssnested cssreactcopymodulesfantasy-landjsdomexectermcomputed-typeswrapdefinepatchreadablestreamamazonesregexsuperstructes5writeUint32ArraydeepclonetypeofposeruntimewhichoffsetformatjsxCSSStyleDeclarationiteratorslotless mixinstaskjson-schema-validationcolorcollectionsignalURLObservablesexitrobuststylecallbindfindLastJSON-SchemastringifierfullsameValueZerothroat
1.0.5

6 days ago

1.0.4

7 days ago

1.0.3

8 days ago

1.0.2

9 days ago

1.0.1

10 days ago

1.0.0

10 days ago