cleye
Strongly typed CLI development for Node.js
README

cleye
The intuitive command-line interface (CLI) development tool.
Features
Minimal API surface
Powerful flag parsing
Strongly typed parameters and flags
Command support
Help documentation generation (customizable too!)
Install
- ``` shell
- npm i cleye
- ```
About
Cleyemakes it very easy to develop command-line scripts in Node.js. It handles argv parsing to give you strongly typed parameters + flags and generates --helpdocumentation based on the provided information.
greet.js:
- ``` ts
- import { cli } from 'cleye'
- // Parse argv
- const argv = cli({
- name: 'greet.js',
- // Define parameters
- parameters: [
- '<first name>', // First name is required
- '[last name]' // Last name is optional
- ],
- // Define flags/options
- flags: {
- // Parses `--time` as a string
- time: {
- type: String,
- description: 'Time of day to greet (morning or evening)',
- default: 'morning'
- }
- }
- })
- const name = [argv._.firstName, argv._.lastName].filter(Boolean).join(' ')
- if (argv.flags.time === 'morning') {
- console.log(`Good morning ${name}!`)
- } else {
- console.log(`Good evening ${name}!`)
- }
- ```
🛠 In development, type hints are provided on parsed flags and parameters:
Type hints for Cleye's output are very verbose and readable📖 Generated help documentation can be viewed with the --helpflag:
- ``` shell
- $ node greet.js --help
- greet.js
- Usage:
- greet.js [flags...] <first name> [last name]
- Flags:
- -h, --help Show help
- --time <string> Time of day to greet (morning or evening) (default: "morning")
- ```
✅ Run the script to see it in action:
- ``` shell
- $ node greet.js John Doe --time evening
- Good evening John Doe!
- ```
Examples
Want to dive right into some code? Check out some of these examples:
greet.js : Working example from above
npm install : Reimplementation of npm install 's CLI
tsc : Reimplementation of TypeScript tsc 's CLI
snap-tweet : Reimplementation of snap-tweet 's CLI
pkg-size : Reimplementation of pkg-size 's CLI
探客时代
