09 May 2023 07:15:13 UTC">3 years ago css-selection.js 77628cf8bf first comm 3 years ago css-shapes.js 77628cf8bf first comm 3 years ago css-snappoints.js 77628cf8bf first comm 3 years ago css-sticky.js 77628cf8bf first comm 3 years ago css-subgrid.js 77628cf8bf first comm 3 years ago css-supports-api.js 77628cf8bf first comm 3 years ago css-table.js 77628cf8bf first comm 3 years ago css-text-align-last.js 77628cf8bf first comm 3 years ago css-text-box-trim.js 77628cf8bf first comm 3 years ago css-text-indent.js 77628cf8bf first comm 3 years ago css-text-justify.js 77628cf8bf first comm 3 years ago css-text-orientation.js 77628cf8bf first comm 3 years ago css-text-spacing.js 77628cf8bf first comm 3 years ago css-textshadow.js 77628cf8bf first comm 3 years ago css-touch-action.js 77628cf8bf first comm 3 years ago css-transitions.js 77628cf8bf first comm 3 years ago css-unicode-bidi.js 77628cf8bf first comm 3 years ago css-unset-value.js 77628cf8bf first comm 3 years ago css-variables.js 77628cf8bf first comm 3 years ago css-when-else.js 77628cf8bf first comm 3 years ago css-widows-orphans.js 77628cf8bf first comm 3 years ago css-width-stretch.js 77628cf8bf first comm 3 years ago css-writing-mode.js 77628cf8bf first comm 3 years ago css-zoom.js 77628cf8bf first comm 3 years ago css3-attr.js 77628cf8bf first comm 3 years ago css3-boxsizing.js 77628cf8bf first comm 3 years ago css3-colors.js 77628cf8bf first comm 3 years ago css3-cursors-grab.js 77628cf8bf first comm 3 years ago css3-cursors-newer.js 77628cf8bf first comm 3 years ago css3-cursors.js 77628cf8bf first comm 3 years ago css3-tabsize.js 77628cf8bf first comm 3 years ago currentcolor.js 77628cf8bf first comm 3 years ago custom-elements.js 77628cf8bf first comm 3 years ago custom-elementsv1.js 77628cf8bf first comm 3 years ago customevent.js 77628cf8bf first comm 3 years ago datalist.js 77628cf8bf first comm 3 years ago dataset.js 77628cf8bf first comm 3 years ago datauri.js 77628cf8bf first comm 3 years ago date-tolocaledatestring.js 77628cf8bf first comm 3 years ago declarative-shadow-dom.js 77628cf8bf first comm 3 years ago decorators.js 77628cf8bf first comm 3 years ago details.js 77628cf8bf first comm 3 years ago deviceorientation.js 77628cf8bf first comm 3 years ago devicepixelratio.js 77628cf8bf first comm 3 years ago dialog.js 77628cf8bf first comm 3 years ago dispatchevent.js 77628cf8bf first comm 3 years ago dnssec.js 77628cf8bf first comm 3 years ago do-not-track.js 77628cf8bf first comm 3 years ago document-currentscript.js 77628cf8bf first comm 3 years ago document-evaluate-xpath.js 77628cf8bf first comm 3 years ago document-execcommand.js 77628cf8bf first comm 3 years ago document-policy.js 77628cf8bf first comm 3 years ago document-scrollingelement.js 77628cf8bf first comm 3 years ago documenthead.js 77628cf8bf first comm 3 years ago dom-manip-convenience.js 77628cf8bf first comm 3 years ago dom-range.js 77628cf8bf first comm 3 years ago domcontentloaded.js 77628cf8bf first comm 3 years ago dommatrix.js 77628cf8bf first comm 3 years ago download.js 77628cf8bf first comm 3 years ago dragndrop.js 77628cf8bf first comm 3 years ago element-closest.js 77628cf8bf first comm 3 years ago element-from-point.js 77628cf8bf first comm 3 years ago element-scroll-methods.js 77628cf8bf first comm 3 years ago eme.js 77628cf8bf first comm 3 years ago eot.js 77628cf8bf first comm 3 years ago es5.js 77628cf8bf first comm 3 years ago es6-class.js 77628cf8bf first comm 3 years ago es6-generators.js 77628cf8bf first comm 3 years ago es6-module-dynamic-import.js 77628cf8bf first comm 3 years ago es6-module.js 77628cf8bf first comm 3 years ago es6-number.js 77628cf8bf first comm 3 years ago es6-string-includes.js 77628cf8bf first comm 3 years ago es6.js 77628cf8bf first comm 3 years ago eventsource.js 77628cf8bf first comm 3 years ago extended-system-fonts.js 77628cf8bf first comm 3 years ago feature-policy.js 77628cf8bf first comm 3 years ago fetch.js 77628cf8bf first comm 3 years ago fieldset-disabled.js 77628cf8bf first comm 3 years ago fileapi.js 77628cf8bf first comm 3 years ago filereader.js 77628cf8bf first comm 3 years ago filereadersync.js 77628cf8bf first comm 3 years ago filesystem.js 77628cf8bf first comm 3 years ago flac.js 77628cf8bf first comm 3 years ago flexbox-gap.js 77628cf8bf first comm 3 years ago flexbox.js 77628cf8bf first comm 3 years ago flow-root.js 77628cf8bf first comm 3 years ago focusin-focusout-events.js 77628cf8bf first comm 3 years ago font-family-system-ui.js 77628cf8bf first comm 3 years ago font-feature.js 77628cf8bf first comm 3 years ago font-kerning.js 77628cf8bf first comm 3 years ago font-loading.js 77628cf8bf first comm 3 years ago font-size-adjust.js 77628cf8bf first comm 3 years ago font-smooth.js 77628cf8bf first comm 3 years ago font-unicode-range.js 77628cf8bf first comm 3 years ago font-variant-alternates.js 77628cf8bf first comm 3 years ago font-variant-numeric.js 77628cf8bf first comm 3 years ago fontface.js 77628cf8bf first comm 3 years ago form-attribute.js 77628cf8bf first comm 3 years ago form-submit-attributes.js 77628cf8bf first comm 3 years ago form-validation.js 77628cf8bf first comm 3 years ago forms.js 77628cf8bf first comm 3 years ago fullscreen.js 77628cf8bf first comm 3 years ago gamepad.js 77628cf8bf first comm 3 years ago geolocation.js 77628cf8bf first comm 3 years ago getboundingclientrect.js 77628cf8bf first comm 3 years ago getcomputedstyle.js 77628cf8bf first comm 3 years ago getelementsbyclassname.js 77628cf8bf first comm 3 years ago getrandomvalues.js 77628cf8bf first comm 3 years ago gyroscope.js 77628cf8bf first comm 3 years ago hardwareconcurrency.js 77628cf8bf first comm 3 years ago hashchange.js 77628cf8bf first comm 3 years ago heif.js 77628cf8bf first comm 3 years ago hevc.js 77628cf8bf first comm 3 years ago hidden.js 77628cf8bf first comm 3 years ago high-resolution-time.js 77628cf8bf first comm 3 years ago history.js 77628cf8bf first comm 3 years ago html-media-capture.js 77628cf8bf first comm 3 years ago html5semantic.js 77628cf8bf first comm 3 years ago http-live-streaming.js 77628cf8bf first comm 3 years ago http2.js 77628cf8bf first comm 3 years ago http3.js 77628cf8bf first comm 3 years ago iframe-sandbox.js 77628cf8bf first comm 3 years ago iframe-seamless.js 77628cf8bf first comm 3 years ago iframe-srcdoc.js 77628cf8bf first comm 3 years ago imagecapture.js 77628cf8bf first comm 3 years ago ime.js 77628cf8bf first comm 3 years ago img-naturalwidth-naturalheight.js 77628cf8bf first comm 3 years ago import-maps.js 77628cf8bf first comm 3 years ago imports.js 77628cf8bf first comm 3 years ago indeterminate-checkbox.js 77628cf8bf first comm 3 years ago indexeddb.js 77628cf8bf first comm 3 years ago indexeddb2.js 77628cf8bf first comm 3 years ago inline-block.js 77628cf8bf first comm 3 years ago innertext.js 77628cf8bf first comm 3 years ago input-autocomplete-onoff.js 77628cf8bf first comm 3 years ago input-color.js 77628cf8bf first comm 3 years ago input-datetime.js 77628cf8bf first comm 3 years ago input-email-tel-url.js 77628cf8bf first comm 3 years ago input-event.js 77628cf8bf first comm 3 years ago input-file-accept.js 77628cf8bf first comm 3 years ago input-file-directory.js 77628cf8bf first comm 3 years ago input-file-multiple.js 77628cf8bf first comm 3 years ago input-inputmode.js 77628cf8bf first comm 3 years ago input-minlength.js 77628cf8bf first comm 3 years ago input-number.js 77628cf8bf first comm 3 years ago input-pattern.js 77628cf8bf first comm 3 years ago input-placeholder.js 77628cf8bf first comm 3 years ago input-range.js 77628cf8bf first comm 3 years ago input-search.js 77628cf8bf first comm 3 years ago input-selection.js 77628cf8bf first comm 3 years ago insert-adjacent.js 77628cf8bf first comm 3 years ago insertadjacenthtml.js 77628cf8bf first comm 3 years ago internationalization.js 77628cf8bf first comm 3 years ago intersectionobserver-v2.js 77628cf8bf first comm 3 years ago intersectionobserver.js 77628cf8bf first comm 3 years ago intl-pluralrules.js 77628cf8bf first comm 3 years ago intrinsic-width.js 77628cf8bf first comm 3 years ago jpeg2000.js 77628cf8bf first comm 3 years ago jpegxl.js 77628cf8bf first comm 3 years ago jpegxr.js 77628cf8bf first comm 3 years ago js-regexp-lookbehind.js 77628cf8bf first comm 3 years ago json.js 77628cf8bf first comm 3 years ago justify-content-space-evenly.js 77628cf8bf first comm 3 years ago kerning-pairs-ligatures.js 77628cf8bf first comm 3 years ago keyboardevent-charcode.js 77628cf8bf first comm 3 years ago keyboardevent-code.js 77628cf8bf first comm 3 years ago keyboardevent-getmodifierstate.js 77628cf8bf first comm 3 years ago keyboardevent-key.js 77628cf8bf first comm 3 years ago keyboardevent-location.js 77628cf8bf first comm 3 years ago keyboardevent-which.js 77628cf8bf first comm 3 years ago lazyload.js 77628cf8bf first comm 3 years ago let.js 77628cf8bf first comm 3 years ago link-icon-png.js 77628cf8bf first comm 3 years ago link-icon-svg.js 77628cf8bf first comm 3 years ago link-rel-dns-prefetch.js 77628cf8bf first comm 3 years ago link-rel-modulepreload.js 77628cf8bf first comm 3 years ago link-rel-preconnect.js 77628cf8bf first comm 3 years ago link-rel-prefetch.js 77628cf8bf first comm 3 years ago link-rel-preload.js 77628cf8bf first comm 3 years ago link-rel-prerender.js 77628cf8bf first comm 3 years ago loading-lazy-attr.js 77628cf8bf first comm 3 years ago localecompare.js 77628cf8bf first comm 3 years ago magnetometer.js 77628cf8bf first comm 3 years ago matchesselector.js 77628cf8bf first comm 3 years ago matchmedia.js 77628cf8bf first comm 3 years ago mathml.js 77628cf8bf first comm 3 years ago maxlength.js 77628cf8bf first comm 3 years ago mdn-css-unicode-bidi-isolate-override.js 77628cf8bf first comm 3 years ago mdn-css-unicode-bidi-isolate.js 77628cf8bf first comm 3 years ago mdn-css-unicode-bidi-plaintext.js 77628cf8bf first comm 3 years ago mdn-text-decoration-color.js 77628cf8bf first comm 3 years ago mdn-text-decoration-line.js 77628cf8bf first comm 3 years ago mdn-text-decoration-shorthand.js 77628cf8bf first comm 3 years ago mdn-text-decoration-style.js 77628cf8bf first comm 3 years ago media-fragments.js 77628cf8bf first comm 3 years ago mediacapture-fromelement.js 77628cf8bf first comm 3 years ago mediarecorder.js 77628cf8bf first comm 3 years ago mediasource.js 77628cf8bf first comm 3 years ago menu.js 77628cf8bf first comm 3 years ago meta-theme-color.js 77628cf8bf first comm 3 years ago meter.js 77628cf8bf first comm 3 years ago midi.js 77628cf8bf first comm 3 years ago minmaxwh.js 77628cf8bf first comm 3 years ago mp3.js 77628cf8bf first comm 3 years ago mpeg-dash.js 77628cf8bf first comm 3 years ago mpeg4.js 77628cf8bf first comm 3 years ago multibackgrounds.js 77628cf8bf first comm 3 years ago multicolumn.js 77628cf8bf first comm 3 years ago mutation-events.js 77628cf8bf first comm 3 years ago mutationobserver.js 77628cf8bf first comm 3 years ago namevalue-storage.js 77628cf8bf first comm 3 years ago native-filesystem-api.js 77628cf8bf first comm 3 years ago nav-timing.js 77628cf8bf first comm 3 years ago netinfo.js 77628cf8bf first comm 3 years ago notifications.js 77628cf8bf first comm 3 years ago object-entries.js 77628cf8bf first comm 3 years ago object-fit.js 77628cf8bf first comm 3 years ago object-observe.js 77628cf8bf first comm 3 years ago object-values.js 77628cf8bf first comm 3 years ago objectrtc.js 77628cf8bf first comm 3 years ago offline-apps.js 77628cf8bf first comm 3 years ago offscreencanvas.js 77628cf8bf first comm 3 years ago ogg-vorbis.js 77628cf8bf first comm 3 years ago ogv.js 77628cf8bf first comm 3 years ago ol-reversed.js 77628cf8bf first comm 3 years ago once-event-listener.js 77628cf8bf first comm 3 years ago online-status.js 77628cf8bf first comm 3 years ago opus.js 77628cf8bf first comm 3 years ago orientation-sensor.js 77628cf8bf first comm 3 years ago outline.js 77628cf8bf first comm 3 years ago pad-start-end.js 77628cf8bf first comm 3 years ago page-transition-events.js 77628cf8bf first comm 3 years ago pagevisibility.js 77628cf8bf first comm 3 years ago passive-event-listener.js 77628cf8bf first comm 3 years ago passwordrules.js 77628cf8bf first comm 3 years ago path2d.js 77628cf8bf first comm 3 years ago payment-request.js 77628cf8bf first comm 3 years ago pdf-viewer.js 77628cf8bf first comm 3 years ago permissions-api.js 77628cf8bf first comm 3 years ago permissions-policy.js 77628cf8bf first comm 3 years ago picture-in-picture.js 77628cf8bf first comm 3 years ago picture.js 77628cf8bf first comm 3 years ago ping.js 77628cf8bf first comm 3 years ago png-alpha.js 77628cf8bf first comm 3 years ago pointer-events.js 77628cf8bf first comm 3 years ago pointer.js 77628cf8bf first comm 3 years ago pointerlock.js 77628cf8bf first comm 3 years ago portals.js 77628cf8bf first comm 3 years ago prefers-color-scheme.js 77628cf8bf first comm 3 years ago prefers-reduced-motion.js 77628cf8bf first comm 3 years ago progress.js 77628cf8bf first comm 3 years ago promise-finally.js 77628cf8bf first comm 3 years ago promises.js 77628cf8bf first comm 3 years ago proximity.js 77628cf8bf first comm 3 years ago proxy.js 77628cf8bf first comm 3 years ago publickeypinning.js 77628cf8bf first comm 3 years ago push-api.js 77628cf8bf first comm 3 years ago queryselector.js 77628cf8bf first comm 3 years ago readonly-attr.js 77628cf8bf first comm 3 years ago referrer-policy.js 77628cf8bf first comm 3 years ago registerprotocolhandler.js 77628cf8bf first comm 3 years ago rel-noopener.js 77628cf8bf first comm 3 years ago rel-noreferrer.js 77628cf8bf first comm 3 years ago rellist.js 77628cf8bf first comm 3 years ago rem.js 77628cf8bf first comm 3 years ago requestanimationframe.js 77628cf8bf first comm 3 years ago requestidlecallback.js 77628cf8bf first comm 3 years ago resizeobserver.js 77628cf8bf first comm 3 years ago resource-timing.js 77628cf8bf first comm 3 years ago rest-parameters.js 77628cf8bf first comm 3 years ago rtcpeerconnection.js 77628cf8bf first comm 3 years ago ruby.js 77628cf8bf first comm 3 years ago run-in.js 77628cf8bf first comm 3 years ago same-site-cookie-attribute.js 77628cf8bf first comm 3 years ago screen-orientation.js 77628cf8bf first comm 3 years ago script-async.js 77628cf8bf first comm 3 years ago script-defer.js 77628cf8bf first comm 3 years ago scrollintoview.js 77628cf8bf first comm 3 years ago scrollintoviewifneeded.js 77628cf8bf first comm 3 years ago sdch.js 77628cf8bf first comm 3 years ago selection-api.js 77628cf8bf first comm 3 years ago server-timing.js 77628cf8bf first comm 3 years ago serviceworkers.js 77628cf8bf first comm 3 years ago setimmediate.js 77628cf8bf first comm 3 years ago shadowdom.js 77628cf8bf first comm 3 years ago shadowdomv1.js 77628cf8bf first comm 3 years ago sharedarraybuffer.js 77628cf8bf first comm 3 years ago sharedworkers.js 77628cf8bf first comm 3 years ago sni.js 77628cf8bf first comm 3 years ago spdy.js 77628cf8bf first comm 3 years ago speech-recognition.js 77628cf8bf first comm 3 years ago speech-synthesis.js 77628cf8bf first comm 3 years ago spellcheck-attribute.js 77628cf8bf first comm 3 years ago sql-storage.js 77628cf8bf first comm 3 years ago srcset.js 77628cf8bf first comm 3 years ago stream.js 77628cf8bf first comm 3 years ago streams.js 77628cf8bf first comm 3 years ago stricttransportsecurity.js 77628cf8bf first comm 3 years ago style-scoped.js 77628cf8bf first comm 3 years ago subresource-bundling.js 77628cf8bf first comm 3 years ago subresource-integrity.js 77628cf8bf first comm 3 years ago svg-css.js 77628cf8bf first comm 3 years ago svg-filters.js 77628cf8bf first comm 3 years ago svg-fonts.js 77628cf8bf first comm 3 years ago svg-fragment.js 77628cf8bf first comm 3 years ago svg-html.js 77628cf8bf first comm 3 years ago svg-html5.js 77628cf8bf first comm 3 years ago svg-img.js 77628cf8bf first comm 3 years ago svg-smil.js 77628cf8bf first comm 3 years ago svg.js 77628cf8bf first comm 3 years ago sxg.js 77628cf8bf first comm 3 years ago tabindex-attr.js 77628cf8bf first comm 3 years ago template-literals.js 77628cf8bf first comm 3 years ago template.js 77628cf8bf first comm 3 years ago temporal.js 77628cf8bf first comm 3 years ago testfeat.js 77628cf8bf first comm 3 years ago text-decoration.js 77628cf8bf first comm 3 years ago text-emphasis.js 77628cf8bf first comm 3 years ago text-overflow.js 77628cf8bf first comm 3 years ago text-size-adjust.js 77628cf8bf first comm 3 years ago text-stroke.js 77628cf8bf first comm 3 years ago textcontent.js 77628cf8bf first comm 3 years ago textencoder.js 77628cf8bf first comm 3 years ago tls1-1.js 77628cf8bf first comm 3 years ago tls1-2.js 77628cf8bf first comm 3 years ago tls1-3.js 77628cf8bf first comm 3 years ago touch.js 77628cf8bf first comm 3 years ago transforms2d.js 77628cf8bf first comm 3 years ago transforms3d.js 77628cf8bf first comm 3 years ago trusted-types.js 77628cf8bf first comm 3 years ago ttf.js 77628cf8bf first comm 3 years ago typedarrays.js 77628cf8bf first comm 3 years ago u2f.js 77628cf8bf first comm 3 years ago unhandledrejection.js 77628cf8bf first comm 3 years ago upgradeinsecurerequests.js 77628cf8bf first comm 3 years ago url-scroll-to-text-fragment.js 77628cf8bf first comm 3 years ago url.js 77628cf8bf first comm 3 years ago urlsearchparams.js 77628cf8bf first comm 3 years ago use-strict.js 77628cf8bf first comm 3 years ago user-select-none.js 77628cf8bf first comm 3 years ago user-timing.js 77628cf8bf first comm 3 years ago variable-fonts.js 77628cf8bf first comm 3 years ago vector-effect.js 77628cf8bf first comm 3 years ago vibration.js 77628cf8bf first comm 3 years ago video.js 77628cf8bf first comm 3 years ago videotracks.js 77628cf8bf first comm 3 years ago viewport-unit-variants.js 77628cf8bf first comm 3 years ago viewport-units.js 77628cf8bf first comm 3 years ago wai-aria.js 77628cf8bf first comm 3 years ago wake-lock.js 77628cf8bf first comm 3 years ago wasm.js 77628cf8bf first comm 3 years ago wav.js 77628cf8bf first comm 3 years ago wbr-element.js 77628cf8bf first comm 3 years ago web-animation.js 77628cf8bf first comm 3 years ago web-app-manifest.js 77628cf8bf first comm 3 years ago web-bluetooth.js 77628cf8bf first comm 3 years ago web-serial.js 77628cf8bf first comm 3 years ago web-share.js 77628cf8bf first comm 3 years ago webauthn.js 77628cf8bf first comm 3 years ago webcodecs.js 77628cf8bf first comm 3 years ago webgl.js 77628cf8bf first comm 3 years ago webgl2.js 77628cf8bf first comm 3 years ago webgpu.js 77628cf8bf first comm 3 years ago webhid.js 77628cf8bf first comm 3 years ago webkit-user-drag.js 77628cf8bf first comm 3 years ago webm.js 77628cf8bf first comm 3 years ago webnfc.js 77628cf8bf first comm 3 years ago webp.js 77628cf8bf first comm 3 years ago websockets.js 77628cf8bf first comm 3 years ago webtransport.js 77628cf8bf first comm 3 years ago webusb.js 77628cf8bf first comm 3 years ago webvr.js 77628cf8bf first comm 3 years ago webvtt.js 77628cf8bf first comm 3 years ago webworkers.js 77628cf8bf first comm 3 years ago webxr.js 77628cf8bf first comm 3 years ago will-change.js 77628cf8bf first comm 3 years ago woff.js 77628cf8bf first comm 3 years ago woff2.js 77628cf8bf first comm 3 years ago word-break.js 77628cf8bf first comm 3 years ago wordwrap.js 77628cf8bf first comm 3 years ago x-doc-messaging.js 77628cf8bf first comm 3 years ago x-frame-options.js 77628cf8bf first comm 3 years ago xhr2.js 77628cf8bf first comm 3 years ago xhtml.js 77628cf8bf first comm 3 years ago xhtmlsmil.js 77628cf8bf first comm 3 years ago xml-serializer.js 77628cf8bf first comm 3 years ago tum/tmt_learning - Gogs: Simplico Git Service

Ei kuvausta

Prach Pongpanich 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
..
typings 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
CHANGELOG.md 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
LICENSE 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
Readme.md 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
index.js 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten
package.json 6f337d0a21 install tailwind alpine daisyui 3 vuotta sitten

Readme.md

Commander.js

Build Status NPM Version NPM Downloads Install Size

The complete solution for node.js command-line interfaces, inspired by Ruby's commander.

Read this in other languages: English | 简体中文

Installation

npm install commander

Declaring program variable

Commander exports a global object which is convenient for quick programs. This is used in the examples in this README for brevity.

const program = require('commander');
program.version('0.0.1');

For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use.

 const commander = require('commander');
 const program = new commander.Command();
 program.version('0.0.1');

Options

Options are defined with the .option() method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space.

The options can be accessed as properties on the Command object. Multi-word options such as "--template-engine" are camel-cased, becoming program.templateEngine etc. Multiple short flags may be combined as a single arg, for example -abc is equivalent to -a -b -c.

See also optional new behaviour to avoid name clashes.

Common option types, boolean and value

The two most used option types are a boolean flag, and an option which takes a value (declared using angle brackets). Both are undefined unless specified on command line.

const program = require('commander');

program
  .option('-d, --debug', 'output extra debugging')
  .option('-s, --small', 'small pizza size')
  .option('-p, --pizza-type <type>', 'flavour of pizza');

program.parse(process.argv);

if (program.debug) console.log(program.opts());
console.log('pizza details:');
if (program.small) console.log('- small pizza size');
if (program.pizzaType) console.log(`- ${program.pizzaType}`);
$ pizza-options -d
{ debug: true, small: undefined, pizzaType: undefined }
pizza details:
$ pizza-options -p
error: option '-p, --pizza-type <type>' argument missing
$ pizza-options -ds -p vegetarian
{ debug: true, small: true, pizzaType: 'vegetarian' }
pizza details:
- small pizza size
- vegetarian
$ pizza-options --pizza-type=cheese
pizza details:
- cheese

program.parse(arguments) processes the arguments, leaving any args not consumed by the options as the program.args array.

Default option value

You can specify a default value for an option which takes a value.

const program = require('commander');

program
  .option('-c, --cheese <type>', 'add the specified type of cheese', 'blue');

program.parse(process.argv);

console.log(`cheese: ${program.cheese}`);
$ pizza-options
cheese: blue
$ pizza-options --cheese stilton
cheese: stilton

Other option types, negatable boolean and flag|value

You can specify a boolean option long name with a leading no- to set the option value to false when used. Defined alone this also makes the option true by default.

If you define --foo first, adding --no-foo does not change the default value from what it would otherwise be. You can specify a default boolean value for a boolean flag and it can be overridden on command line.

const program = require('commander');

program
  .option('--no-sauce', 'Remove sauce')
  .option('--cheese <flavour>', 'cheese flavour', 'mozzarella')
  .option('--no-cheese', 'plain with no cheese')
  .parse(process.argv);

const sauceStr = program.sauce ? 'sauce' : 'no sauce';
const cheeseStr = (program.cheese === false) ? 'no cheese' : `${program.cheese} cheese`;
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
$ pizza-options
You ordered a pizza with sauce and mozzarella cheese
$ pizza-options --sauce
error: unknown option '--sauce'
$ pizza-options --cheese=blue
You ordered a pizza with sauce and blue cheese
$ pizza-options --no-sauce --no-cheese
You ordered a pizza with no sauce and no cheese

You can specify an option which functions as a flag but may also take a value (declared using square brackets).

const program = require('commander');

program
  .option('-c, --cheese [type]', 'Add cheese with optional type');

program.parse(process.argv);

if (program.cheese === undefined) console.log('no cheese');
else if (program.cheese === true) console.log('add cheese');
else console.log(`add cheese type ${program.cheese}`);
$ pizza-options
no cheese
$ pizza-options --cheese
add cheese
$ pizza-options --cheese mozzarella
add cheese type mozzarella

Custom option processing

You may specify a function to do custom processing of option values. The callback function receives two parameters, the user specified value and the previous value for the option. It returns the new value for the option.

This allows you to coerce the option value to the desired type, or accumulate values, or do entirely custom processing.

You can optionally specify the default/starting value for the option after the function.

const program = require('commander');

function myParseInt(value, dummyPrevious) {
  // parseInt takes a string and an optional radix
  return parseInt(value);
}

function increaseVerbosity(dummyValue, previous) {
  return previous + 1;
}

function collect(value, previous) {
  return previous.concat([value]);
}

function commaSeparatedList(value, dummyPrevious) {
  return value.split(',');
}

program
  .option('-f, --float <number>', 'float argument', parseFloat)
  .option('-i, --integer <number>', 'integer argument', myParseInt)
  .option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0)
  .option('-c, --collect <value>', 'repeatable value', collect, [])
  .option('-l, --list <items>', 'comma separated list', commaSeparatedList)
;

program.parse(process.argv);

if (program.float !== undefined) console.log(`float: ${program.float}`);
if (program.integer !== undefined) console.log(`integer: ${program.integer}`);
if (program.verbose > 0) console.log(`verbosity: ${program.verbose}`);
if (program.collect.length > 0) console.log(program.collect);
if (program.list !== undefined) console.log(program.list);
$ custom -f 1e2
float: 100
$ custom --integer 2
integer: 2
$ custom -v -v -v
verbose: 3
$ custom -c a -c b -c c
[ 'a', 'b', 'c' ]
$ custom --list x,y,z
[ 'x', 'y', 'z' ]

Required option

You may specify a required (mandatory) option using .requiredOption. The option must be specified on the command line, or by having a default value. The method is otherwise the same as .option in format, taking flags and description, and optional default value or custom processing.

const program = require('commander');

program
  .requiredOption('-c, --cheese <type>', 'pizza must have cheese');

program.parse(process.argv);
$ pizza
error: required option '-c, --cheese <type>' not specified

Version option

The optional version method adds handling for displaying the command version. The default option flags are -V and --version, and when present the command prints the version number and exits.

program.version('0.0.1');
$ ./examples/pizza -V
0.0.1

You may change the flags and description by passing additional parameters to the version method, using the same syntax for flags as the option method. The version flags can be named anything, but a long name is required.

program.version('0.0.1', '-v, --vers', 'output the current version');

Commands

You can specify (sub)commands for your top-level command using .command. There are two ways these can be implemented: using an action handler attached to the command, or as a separate executable file (described in more detail later). In the first parameter to .command you specify the command name and any command arguments. The arguments may be <required> or [optional], and the last argument may also be variadic....

For example:

// Command implemented using action handler (description is supplied separately to `.command`)
// Returns new command for configuring.
program
  .command('clone <source> [destination]')
  .description('clone a repository into a newly created directory')
  .action((source, destination) => {
    console.log('clone command called');
  });

// Command implemented using separate executable file (description is second parameter to `.command`)
// Returns top-level command for adding more commands.
program
  .command('start <service>', 'start named service')
  .command('stop [service]', 'stop named service, or all if no name supplied');

Specify the argument syntax

You use .arguments to specify the arguments for the top-level command, and for subcommands they are included in the .command call. Angled brackets (e.g. <required>) indicate required input. Square brackets (e.g. [optional]) indicate optional input.

const program = require('commander');

program
  .version('0.1.0')
  .arguments('<cmd> [env]')
  .action(function (cmd, env) {
    cmdValue = cmd;
    envValue = env;
  });

program.parse(process.argv);

if (typeof cmdValue === 'undefined') {
  console.error('no command given!');
  process.exit(1);
}
console.log('command:', cmdValue);
console.log('environment:', envValue || "no environment given");

The last argument of a command can be variadic, and only the last argument. To make an argument variadic you append ... to the argument name. For example:

const program = require('commander');

program
  .version('0.1.0')
  .command('rmdir <dir> [otherDirs...]')
  .action(function (dir, otherDirs) {
    console.log('rmdir %s', dir);
    if (otherDirs) {
      otherDirs.forEach(function (oDir) {
        console.log('rmdir %s', oDir);
      });
    }
  });

program.parse(process.argv);

The variadic argument is passed to the action handler as an array. (And this also applies to program.args.)

Action handler (sub)commands

You can add options to a command that uses an action handler. The action handler gets passed a parameter for each argument you declared, and one additional argument which is the command object itself. This command argument has the values for the command-specific options added as properties.

const program = require('commander');

program
  .command('rm <dir>')
  .option('-r, --recursive', 'Remove recursively')
  .action(function (dir, cmdObj) {
    console.log('remove ' + dir + (cmdObj.recursive ? ' recursively' : ''))
  })

program.parse(process.argv)

You may supply an async action handler, in which case you call .parseAsync rather than .parse.

async function run() { /* code goes here */ }

async function main() {
  program
    .command('run')
    .action(run);
  await program.parseAsync(process.argv);
}

A command's options on the command line are validated when the command is used. Any unknown options will be reported as an error. However, if an action-based command does not define an action, then the options are not validated.

Configuration options can be passed with the call to .command(). Specifying true for opts.noHelp will remove the command from the generated help output.

Git-style executable (sub)commands

When .command() is invoked with a description argument, this tells commander that you're going to use separate executables for sub-commands, much like git(1) and other popular tools. Commander will search the executables in the directory of the entry script (like ./examples/pm) with the name program-subcommand, like pm-install, pm-search. You can specify a custom name with the executableFile configuration option.

You handle the options for an executable (sub)command in the executable, and don't declare them at the top-level.

// file: ./examples/pm
const program = require('commander');

program
  .version('0.1.0')
  .command('install [name]', 'install one or more packages')
  .command('search [query]', 'search with optional query')
  .command('update', 'update installed packages', {executableFile: 'myUpdateSubCommand'})
  .command('list', 'list packages installed', {isDefault: true})
  .parse(process.argv);

Configuration options can be passed with the call to .command(). Specifying true for opts.noHelp will remove the command from the generated help output. Specifying true for opts.isDefault will run the subcommand if no other subcommand is specified. Specifying a name with executableFile will override the default constructed name.

If the program is designed to be installed globally, make sure the executables have proper modes, like 755.

Automated --help

The help information is auto-generated based on the information commander already knows about your program, so the following --help info is for free:

$ ./examples/pizza --help
Usage: pizza [options]

An application for pizzas ordering

Options:
  -V, --version        output the version number
  -p, --peppers        Add peppers
  -P, --pineapple      Add pineapple
  -b, --bbq            Add bbq sauce
  -c, --cheese <type>  Add the specified type of cheese (default: "marble")
  -C, --no-cheese      You do not want any cheese
  -h, --help           output usage information

Custom help

You can display arbitrary -h, --help information by listening for "--help". Commander will automatically exit once you are done so that the remainder of your program does not execute causing undesired behaviors, for example in the following executable "stuff" will not output when --help is used.

#!/usr/bin/env node

const program = require('commander');

program
  .version('0.1.0')
  .option('-f, --foo', 'enable some foo')
  .option('-b, --bar', 'enable some bar')
  .option('-B, --baz', 'enable some baz');

// must be before .parse() since
// node's emit() is immediate

program.on('--help', function(){
  console.log('')
  console.log('Examples:');
  console.log('  $ custom-help --help');
  console.log('  $ custom-help -h');
});

program.parse(process.argv);

console.log('stuff');

Yields the following help output when node script-name.js -h or node script-name.js --help are run:

Usage: custom-help [options]

Options:
  -h, --help     output usage information
  -V, --version  output the version number
  -f, --foo      enable some foo
  -b, --bar      enable some bar
  -B, --baz      enable some baz

Examples:
  $ custom-help --help
  $ custom-help -h

.usage and .name

These allow you to customise the usage description in the first line of the help. The name is otherwise deduced from the (full) program arguments. Given:

program
  .name("my-command")
  .usage("[global options] command")

The help will start with:

Usage: my-command [global options] command

.outputHelp(cb)

Output help information without exiting. Optional callback cb allows post-processing of help text before it is displayed.

If you want to display help by default (e.g. if no command was provided), you can use something like:

const program = require('commander');
const colors = require('colors');

program
  .version('0.1.0')
  .command('getstream [url]', 'get stream URL')
  .parse(process.argv);

if (!process.argv.slice(2).length) {
  program.outputHelp(make_red);
}

function make_red(txt) {
  return colors.red(txt); //display the help text in red on the console
}

.helpOption(flags, description)

Override the default help flags and description.

program
  .helpOption('-e, --HELP', 'read more information');

.help(cb)

Output help information and exit immediately. Optional callback cb allows post-processing of help text before it is displayed.

Custom event listeners

You can execute custom actions by listening to command and option events.

program.on('option:verbose', function () {
  process.env.VERBOSE = this.verbose;
});

// error on unknown commands
program.on('command:*', function () {
  console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
  process.exit(1);
});

Bits and pieces

Avoiding option name clashes

The original and default behaviour is that the option values are stored as properties on the program, and the action handler is passed a command object with the options values stored as properties. This is very convenient to code, but the downside is possible clashes with existing properties of Command.

There are two new routines to change the behaviour, and the default behaviour may change in the future:

  • storeOptionsAsProperties: whether to store option values as properties on command object, or store separately (specify false) and access using .opts()
  • passCommandToAction: whether to pass command to action handler, or just the options (specify false)
// file: ./examples/storeOptionsAsProperties.action.js
program
  .storeOptionsAsProperties(false)
  .passCommandToAction(false);

program
  .name('my-program-name')
  .option('-n,--name <name>');

program
  .command('show')
  .option('-a,--action <action>')
  .action((options) => {
    console.log(options.action);
  });

program.parse(process.argv);

const programOptions = program.opts();
console.log(programOptions.name);

TypeScript

The Commander package includes its TypeScript Definition file, but also requires the node types which you need to install yourself. e.g.

npm install commander
npm install --save-dev @types/node

If you use ts-node and git-style sub-commands written as .ts files, you need to call your program through node to get the sub-commands called correctly. e.g.

node -r ts-node/register pm.ts

Node options such as --harmony

You can enable --harmony option in two ways:

  • Use #! /usr/bin/env node --harmony in the sub-commands scripts. (Note Windows does not support this pattern.)
  • Use the --harmony option when call the command, like node --harmony examples/pm publish. The --harmony option will be preserved when spawning sub-command process.

Node debugging

If you are using the node inspector for debugging git-style executable (sub)commands using node --inspect et al, the inspector port is incremented by 1 for the spawned subcommand.

Override exit handling

By default Commander calls process.exit when it detects errors, or after displaying the help or version. You can override this behaviour and optionally supply a callback. The default override throws a CommanderError.

The override callback is passed a CommanderError with properties exitCode number, code string, and message. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help is not affected by the override which is called after the display.

program.exitOverride();

try {
  program.parse(process.argv);
} catch (err) {
  // custom processing...
}

Examples

const program = require('commander');

program
  .version('0.1.0')
  .option('-C, --chdir <path>', 'change the working directory')
  .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
  .option('-T, --no-tests', 'ignore test hook');

program
  .command('setup [env]')
  .description('run setup commands for all envs')
  .option("-s, --setup_mode [mode]", "Which setup mode to use")
  .action(function(env, options){
    const mode = options.setup_mode || "normal";
    env = env || 'all';
    console.log('setup for %s env(s) with %s mode', env, mode);
  });

program
  .command('exec <cmd>')
  .alias('ex')
  .description('execute the given remote cmd')
  .option("-e, --exec_mode <mode>", "Which exec mode to use")
  .action(function(cmd, options){
    console.log('exec "%s" using %s mode', cmd, options.exec_mode);
  }).on('--help', function() {
    console.log('');
    console.log('Examples:');
    console.log('');
    console.log('  $ deploy exec sequential');
    console.log('  $ deploy exec async');
  });

program
  .command('*')
  .action(function(env){
    console.log('deploying "%s"', env);
  });

program.parse(process.argv);

More Demos can be found in the examples directory.

License

MIT

Support

Commander 4.x is supported on Node 8 and above, and is likely to work with Node 6 but not tested. (For versions of Node below Node 6, use Commander 3.x or 2.x.)

The main forum for free and community support is the project Issues on GitHub.

Commander for enterprise

Available as part of the Tidelift Subscription

The maintainers of Commander 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.