Command-Line Argument Sorting and Parsing, for JavaScript
CLASP stands for Command-Line Argument Sorting and Parsing. The first CLASP library was a C library with a C++ wrapper. There have been several implementations in other languages. CLASP.js is the JavaScript version.
CLASP stands for Command-Line Argument Sorting and Parsing. The first CLASP library was a C library with a C++ wrapper (see project CLASP). There have been several implementations in other languages. CLASP.js is the JavaScript version.
All CLASP libraries provide facilities for Command Line Interface (CLI) programs as described in the Components section below.
Install using npm install clasp-js.
Use it via require('clasp-js').
NOTE: the name clasp-js follows NPM's package-name rules, but breaks with one of the tips - the one about not including js or node in the name - because there are multiple CLASP libraries, and there already exists a clasp package in NPM.
All CLASP libraries discriminate between three types of command-line arguments:
- flags are hyphen-prefixed arguments that are either present or absent, and hence have a boolean nature;
- options are hyphen-prefixed arguments that are given values; and
- values are non-hyphen-prefixed arguments that represent values.
For example, in the command line
myprog --all -c --opt1=val1 infile outfile
there are:
- two flags,
--alland-c; - one option called
--opt1, which has the valueval1; and - two values,
infileandoutfile.
Flags and options may have aliases. One-letter flags may be combined. Option aliases may specify a value, and may be combined with one-letter flags. UNIX de-facto standard arguments confer specific meanings:
--helpmeans that the program should show the usage/help information and terminate;--versionmeans that the program should show the version information and terminate;--means that all subsequent arguments should be treated as values, regardless of any hyphen-prefixes or embedded=signs.
CLASP.js provides the clasp.specifications module to declare flags and options and their aliases. Use Flag() and Option() to build a specification list, then pass it to clasp.api.parse(). See EXAMPLES.md for worked examples.
CLASP.js provides clasp.usage.showUsage() and clasp.usage.showVersion() to display help and version information and optionally terminate the process. Standard --help and --version specifications are available via clasp.specifications.HELP_FLAG and clasp.specifications.VERSION_FLAG.
Examples are provided in the examples directory, along with a markdown description for each. A detailed list TOC of them is provided in EXAMPLES.md.
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/CLASP.js.
None
CLASP.js is inspired by the C/C++ CLASP library, which is documented in the articles:
- An Introduction to CLASP, Matthew Wilson, CVu, January 2012;
- Anatomy of a CLI Program written in C, Matthew Wilson, CVu, September 2012; and
- Anatomy of a CLI Program written in C++, Matthew Wilson, CVu, September 2015.
Other CLASP libraries include:
CLASP.js is released under the 3-clause BSD license. See LICENSE for details.