@stdlib/cli-ctor

Command-line interface.

https://github.com/stdlib-js/cli-ctor

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.3%) to scientific vocabulary

Keywords

cli command-line interface javascript node node-js nodejs stdlib util utilities utility utils
Last synced: 4 months ago · JSON representation ·

Repository

Command-line interface.

Basic Info
Statistics
  • Stars: 2
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
cli command-line interface javascript node node-js nodejs stdlib util utilities utility utils
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.md

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

CLI

NPM version Build Status Coverage Status <!-- dependencies -->

Command-line interface.

## Installation ```bash npm install @stdlib/cli-ctor ```
## Usage ```javascript var CLI = require( '@stdlib/cli-ctor' ); ``` #### CLI( \[options] ) Command-line interface (CLI) constructor. ```javascript var cli = new CLI(); // returns ``` The constructor accepts the following `options`: - **pkg**: package meta data, such as a `package.json` object. - **version**: command-line interface version. Default: `pkg.version`. - **title**: process title. If set to `true`, the default title is either `pkg.bin.` or `pkg.name`. If set to a `string`, the function sets the process title to the specified string. If set to `false`, the function does not set the process title. - **help**: help text. Default: `''`. - **updates**: `boolean` indicating whether to check if a more recent version of a command-line interface exists in the package registry. In order to check for updates, the function requires both `pkg.name` and `pkg.version` meta data. Default: `true`. - **argv**: an `array` of command-line arguments. Default: `process.argv`. - **options**: command-line argument parser options. To provide package meta data, such as the package `name` and `version`, set the `pkg` option. ```javascript var opts = { 'pkg': require( './package.json' ) }; var cli = new CLI( opts ); // returns ``` To specify a particular command-line interface version (overriding package meta data), set the `version` option. ```javascript var opts = { 'pkg': { 'name': 'beep', 'version': '1.1.1' }, 'version': '1.1.1-beta' }; var cli = new CLI( opts ); // returns cli.version(); // => 1.1.1-beta ``` By default, an instance sets the process title to either the first key in `pkg.bin` or to `pkg.name`. To explicitly set the process title, set the `title` option. ```javascript var proc = require( 'process' ); var opts = { 'title': 'beep-boop' }; var cli = new CLI( opts ); // returns console.log( proc.title ); // => 'beep-boop' ``` To disable setting the process title, set the `title` option to `false`. ```javascript var opts = { 'title': false }; var cli = new CLI( opts ); // returns ``` When the command-line flag `--help` is set, a command-line interface instance prints help text and exits the calling process. To specify the printed text, set the `help` option. ```javascript var opts = { 'help': 'Usage: boop [options] ', 'argv': [ '/usr/local/bin/node', 'foo.js', '--help' ] }; var cli = new CLI( opts ); // => Usage: boop [options] ``` By default, an instance resolves command-line arguments and flags via `process.argv`. To specify a custom set of command-line arguments, set the `argv` option. ```javascript var opts = { 'argv': [ '/usr/local/bin/node', 'foo.js', 'a', 'b', 'c' ] }; var cli = new CLI( opts ); var args = cli.args(); // returns [ 'a', 'b', 'c' ] ``` To specify command-line argument parser options, such as command-line flag types and aliases, set the `options` option. ```javascript var opts = { 'options': { 'boolean': [ 'help', 'version' ], 'string': [ 'output' ], 'alias': { 'help': [ 'h' ], 'version': [ 'V' ], 'output': [ 'o' ] } }, 'argv': [ '/usr/local/bin/node', 'foo.js', '-o=bar.js' ] }; var cli = new CLI( opts ); var flags = cli.flags(); /* returns { 'h': false, 'help': false, 'V': false, 'version': false, 'o': 'bar.js', 'output': 'bar.js' } */ ``` By default, if provided sufficient package meta data (package `name` and `version`), an instance checks whether a newer version of a command-line interface exists in the package registry. If a newer version exists, an instance writes a message to `stdout` indicating that a newer version exists. To disable this check, set the `updates` option to `false`. ```javascript var opts = { 'updates': false }; var cli = new CLI( opts ); // returns ``` * * * ### Prototype Methods #### CLI.prototype.close( \[code] ) Gracefully exits a command-line interface and the calling process. ```javascript var cli = new CLI(); // Gracefully exit: cli.close(); ``` To specify an exit code, provide a `code` argument. ```javascript var cli = new CLI(); // Set the exit code to `1`: cli.close( 1 ); ``` #### CLI.prototype.error( error\[, code] ) Prints an error message to `stderr` and exits a command-line interface and the calling process. ```javascript var cli = new CLI(); // ... // Create a new error object: var err = new Error( 'invalid argument' ); // Exit due to the error: cli.error( err ); ``` When exiting due to an error, the default exit code is `1`. To specify an alternative exit code, provide a `code` argument. ```javascript var cli = new CLI(); // ... // Create a new error object: var err = new Error( 'invalid argument' ); // Exit due to the error: cli.error( err, 2 ); ``` #### CLI.prototype.exit( \[code] ) Forcefully exits a command-line interface and the calling process. ```javascript var cli = new CLI(); // Forcefully exit: cli.exit(); ``` To specify an exit code, provide a `code` argument. ```javascript var cli = new CLI(); // Set the exit code to `1`: cli.exit( 1 ); ``` * * * ### Instance Methods #### cli.args() Returns a list of command-line arguments. ```javascript var cli = new CLI({ 'argv': [ '/usr/local/bin/node', 'foo.js', 'a', '--b', 'c', 'd' ] }); var args = cli.args(); // returns [ 'a', 'd' ] ``` #### cli.flags() Returns command-line flags. ```javascript var cli = new CLI({ 'argv': [ '/usr/local/bin/node', 'foo.js', 'a', '--b', 'c', '-def', '--g=h', 'i' ] }); var flags = cli.flags(); // returns { 'b': 'c', 'd': true, 'e': true, 'f': true, 'g': 'h' } ``` #### cli.help( \[code] ) Prints help text to `stderr` and then exits the calling process. ```javascript var cli = new CLI({ 'help': 'Usage: beep [options] ' }); cli.help(); // => Usage: beep [options] ``` By default, the process exits with an exit code equal to `0`. To exit with a different exit code, provide a `code` argument. #### cli.version() Prints the command-line interface version to `stderr` and then exits the calling process. ```javascript var cli = new CLI({ 'version': '1.1.1' }); cli.version(); // => 1.1.1 ```

## Notes - When either `--help` or `--version` command-line flag is set, a command-line interface instance prints the respective value and then exits the calling process. - When explicitly setting `options.argv`, the first element is reserved for the absolute pathname of the executable which launched the calling process and the second element is reserved for the file path of the executed JavaScript file.

## Examples ```javascript var join = require( 'path' ).join; var readFileSync = require( '@stdlib/fs-read-file' ).sync; var CLI = require( '@stdlib/cli-ctor' ); var main = require( './examples/fixtures/main.js' ); // Load help text: var fopts = { 'encoding': 'utf8' }; var help = readFileSync( join( __dirname, 'examples', 'fixtures', 'usage.txt' ), fopts ); // Set the command-line interface options: var opts = { 'pkg': require( './package.json' ), 'options': require( './examples/fixtures/opts.json' ), 'help': help, 'title': true, 'updates': true }; // Create a new command-line interface: var cli = new CLI( opts ); // Run main: main( 'beep' ); // Close: cli.close( 0 ); ```
* * * ## Notice This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. #### Community [![Chat][chat-image]][chat-url] --- ## License See [LICENSE][stdlib-license]. ## Copyright Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].

Owner

  • Name: stdlib
  • Login: stdlib-js
  • Kind: organization

Standard library for JavaScript.

Citation (CITATION.cff)

cff-version: 1.2.0
title: stdlib
message: >-
  If you use this software, please cite it using the
  metadata from this file.

type: software

authors:
  - name: The Stdlib Authors
    url: https://github.com/stdlib-js/stdlib/graphs/contributors

repository-code: https://github.com/stdlib-js/stdlib
url: https://stdlib.io

abstract: |
  Standard library for JavaScript and Node.js.

keywords:
  - JavaScript
  - Node.js
  - TypeScript
  - standard library
  - scientific computing
  - numerical computing
  - statistical computing

license: Apache-2.0 AND BSL-1.0

date-released: 2016

GitHub Events

Total
  • Push event: 2
Last Year
  • Push event: 2

Committers

Last synced: almost 2 years ago

All Time
  • Total Commits: 44
  • Total Committers: 1
  • Avg Commits per committer: 44.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 17
  • Committers: 1
  • Avg Commits per committer: 17.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
stdlib-bot n****y@s****o 44
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • npm 1,463,027 last-month
  • Total docker downloads: 481,308,706
  • Total dependent packages: 556
    (may contain duplicates)
  • Total dependent repositories: 736
    (may contain duplicates)
  • Total versions: 13
  • Total maintainers: 4
npmjs.org: @stdlib/cli-ctor

Command-line interface.

  • Homepage: https://stdlib.io
  • License: Apache-2.0
  • Latest release: 0.2.2
    published over 1 year ago
  • Versions: 8
  • Dependent Packages: 556
  • Dependent Repositories: 736
  • Downloads: 1,463,027 Last month
  • Docker Downloads: 481,308,706
Rankings
Docker downloads count: 0.1%
Dependent packages count: 0.1%
Downloads: 0.2%
Dependent repos count: 0.7%
Average: 5.2%
Stargazers count: 14.5%
Forks count: 15.4%
Funding
  • type: opencollective
  • url: https://opencollective.com/stdlib
Last synced: 4 months ago
repo1.maven.org: org.mvnpm.at.stdlib:cli-ctor

Command-line interface.

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Average: 41.3%
Dependent packages count: 48.6%
Last synced: 4 months ago

Dependencies

package.json npm
  • @stdlib/assert-instance-of ^0.0.x development
  • @stdlib/assert-is-array ^0.0.x development
  • @stdlib/assert-is-browser ^0.0.x development
  • @stdlib/bench ^0.0.x development
  • @stdlib/fs-read-file ^0.0.x development
  • istanbul ^0.4.1 development
  • proxyquire ^2.0.0 development
  • tap-spec 5.x.x development
  • tape git+https://github.com/kgryte/tape.git#fix/globby development
  • @stdlib/string-format ^0.0.x
  • @stdlib/utils-define-nonenumerable-read-only-property ^0.0.x
  • @stdlib/utils-noop ^0.0.x
  • minimist ^1.2.0
.github/workflows/benchmark.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/close_pull_requests.yml actions
  • superbrothers/close-pull-request v3 composite
.github/workflows/examples.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/npm_downloads.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/publish.yml actions
  • JS-DevTools/npm-publish v1 composite
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/test.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/test_coverage.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • codecov/codecov-action v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/test_install.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite