1.0.0 • Published 11 days ago

@dfgyhujk7npm/veniam-eveniet-illo v1.0.0

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

@dfgyhujk7npm/veniam-eveniet-illo

CI NPM version

CLI arguments parser for node.js, with sub-commands support. Port of python's @dfgyhujk7npm/veniam-eveniet-illo (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('@dfgyhujk7npm/veniam-eveniet-illo')

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.

@dfgyhujk7npm/veniam-eveniet-illo for enterprise

Available as part of the Tidelift Subscription

The maintainers of @dfgyhujk7npm/veniam-eveniet-illo 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.

functionalchannelwarningidlebabelreact-hook-formFunction.prototype.nameloggerfast-clonetouches8es7prettygroupBybyteOffsetutilsMapletparserjson-schema-validationiterateJSON-SchemamiddlewareES2017dropxsswatchsigtermECMAScript 2016monorepopruneURLSearchParamsflattenHyBiStreamponyfillcolumnInt16ArraylrumochakoreantelephoneconcatMapa11yless csshashbannerexetranspileeveryInt32ArrayjestjsmomentduplextrimEndcss lessUint8ClampedArrayWebSockethelperses2017fromgetclass-validatorlintyamlspinnersansicompile lessfiltervariablesforEachsequencepackageeslintconfigfindfunctionsvalidatepackagessymbolgetOwnPropertyDescriptorrandomcircularES2020extensiongetintrinsiclockfilemrumodulescolourless.jsWebSocketsrangeerrorcurrieddependency managerimportsignalsinferenceoptionnegative zerocallbacktesteres6commandphoneutilitiestypanionbusySymbolArray.prototype.flatMaprfc4122json-schema-validatortapeschemeObjectgraphqlcharacterdomtoobjectequalObject.isflagserializeunicodeArray.prototype.flatavaeventEmitterdeterministicfile systemmovewatcherassertsdeepreducervalueES2016hooksconstredactformattingArray.prototype.findLastutilremovefilecompilershimsanitizebootstrap csseventsArray.prototype.filter3ddependenciesjQuerytestreduceArrayBuffer#slicesameValueZerostatelessArray.prototype.containslesscssmatchAllWeakMaplogaccessorviewfindLastdeepcopydeleteassertionnodejsecmascript__proto__genericstaskisartpostcssprotocol-buffersonceECMAScript 2020groupfulli18nerrorESgesturesArray.prototype.flattendefinePropertytc39arktypesetterrequestgradients css3sortednpmparsecollectiontypeofflatspawnjwtequalityuser-streamsoutput-0pipeyupsymlinkstddcssString.prototype.trimmime-dbIteratorschemarapidpropertiesdescriptorsymlinkargsutil.inspectStreamsenvvisualES8enumerableinternaluninstallECMAScript 2018zodobjcorecolorsinternal slotUnderscoreoptimizerweaksetRFC-6455typeECMAScript 2023typescriptECMAScript 2017rateworkspace:*lastquoteObject.definePropertybcryptvariables in cssnamenested cssESnextcode pointses2018springextenddebugtsajvtextcensorrobuststyled-componentsidopenerinstallrequiretrimbreakframercmdfixed-widthnegativeencryptionrm -rfsyntaxtslibhttp.envopensES5getoptreact posefetchnumberprotoECMAScript 3Object.valuesRxJSrm -frnopebootstrap lessmapperformantreadableeditorworkerprivatestylingnativesanitizationconsolepositivetrimLeftReflect.getPrototypeOfvarhandlersmixinsjsxECMAScript 2021look-updatastructurecopypathes-abstractdataviewlookes-shim APIchromiumvalidoptimistdescriptiondirRegExp#flagsES3formatminimaltrimRightcallbindwalkingbundlingxdg-openreact-hookszerocryptowhatwgestreetrimStartsigintmkdirwatchingmulti-packagejsdifftoolkitless mixinsreadablestreamwgetcss nestingBigUint64ArraydescriptorsrmdirES2018pluginlazyCSSStyleDeclarationsidequeueMicrotaskconsumetoSortedratelimitjson-schemawebsitees2015Object.keysvalidatorsettingswritewebpropertycompareES2019typeerrorinputprocessdefineeslintstringifydataViewinterruptsvaluesmkdirptoStringTagcheckasyncUint8ArrayframeworkextradayjspopmotionpyyamlperformancetypedarrayslistenersjasmineaccessibilityMicrosoftwaapiArrayBuffer.prototype.slicepushStyleSheetes-shimscors$.extendspinnerprivate dataslotprotobufpasswordJSONdeepcloneerror-handlingexit-codelanguageformwalkfigletxtermregular expressionTypeScriptpatchfunctionefficientboundarraybufferkeystostringtagoffsetArrayBufferoperating-systemanimationdatastable0folderInt8Arrayfastcopytypesafesuperagentstatussliceglobshebangarraysargumentsfind-uppreprocessorfullwidthcallclientshrinkwrapES2021iteratorconfigfindupes2016configurableautoprefixerObject.assignutilitythroatwordbreakreuseObject.entriesfast-copyreactreal-timemacosreduxtoolsES2023eventDispatchercommanderqsmimetypesflatMapRxfast-deep-copyfastifyterminalless compilercall-bindsetImmediateserializationbrowserlistrmcloneauthconcatresolveES6escapeshellObject.fromEntriestraverseairbnbchinesetypedstyleguideECMAScript 5Float32ArraysymbolsarraywidthbddfastmakejsonpathindicatorstringbatchexpressionString.prototype.matchAllasciicollection.es6omitUint16Arraycontainsasttimebundlerform-validationstreamclasseswindowskarmaexecstylesheetstringifiertacitexecutablebabel-corevestchaiwhichtypesobjectajaxawaitreact-testing-libraryYAMLxhrES2022signalramdaAsyncIteratorisConcatSpreadablepreserve-symlinksstreams2linuxTypedArraysearchrgbiecolumnssortlaunches5hasjsonschemaprogresscoerciblehookformgetPrototypeOfsharedarraybufferinstallerPromiseio-tswritableweakmaptakeguidstarterasserttermcolorstylewraphardlinksdeep-copystreamscliirqprefixwaitreact animationcachemetadatagetteremojidatelengthflagsttyTypeBoxiterationupmimeObservableconcurrencydeep-clonedebuggerbrowserslistArraytyped arrayfsmatchesECMAScript 2022eslint-pluginlinewrappolyfillxdgpersistentpnpm9package.jsonimmerArray.prototype.findLastIndexdefaultregexpReactiveXhasOwnintrinsicargparseloggingthrottleES2015dragloadingsafechromeassignelectronObject.getPrototypeOfemitexitmergeReactiveExtensionsprototype_.extendclassnameArray.prototype.includessetrecursiveparentscommand-linefast-deep-clonecallboundhigher-orderincludesSymbol.toStringTagsuperstructFloat64Arrayentriesruntimebyteparenttranspilerregularcall-boundchildregexenderapiargumentdotenvawesomesauce@@toStringTagECMAScript 2019RegExp.prototype.flagsclassnamesWeakSetmatcheseslintpluginjsoncore-jsbyteLengthURLauthenticationcurlgradients csssomebufferjavascriptgdprnamesjoispecfpapphttpsmkdirstoArrayeast-asian-widthurlsbluebirdbrowserpoint-freestartspeedcjkexpress[[Prototype]]postcss-pluginstructuredClonelinklimiteduuidreadmodulefindLastIndexObservablespurebuffersregular expressionsjapaneseshamfseventsposesharedES7syntaxerrorwordwrapimmutablewatchFileformscomputed-typesECMAScript 6dom-testing-librarylesscss variablefull-widthUint32Arraypromisequerypackage managercss-in-jsqueuepropdirectorycrypturltypedarray
1.0.0

11 days ago