@gruzf/numen-cli
v2.1.21
Published
Easy way to create cli library
Downloads
862
Readme
numen CLI
NUMEN CLI will help you easily and simply create your own cli library using
typescript
. Based on the @gruzf/numen
Install
npm install @gruzf/numen-cli
or
yarn add @gruzf/numen-cli
Usage
First of all, prepare your project structure
.
├── commands
│ ├── commandName1.ts
│ ├── commandName2.ts
│ ├── commandName3.ts
│ └── ...
└── index.ts
./index.ts
#!/usr/bin/env node
import { cli } from "@gruzf/numen-cli";
cli(options);
Options
checkVersion
Show a message about an available new version
- Type:
boolean
- Default:
false
./commands/commandName1.ts
import Command from "@gruzf/numen-cli/command";
export default class CommandName1 extends Command {
description = "My first command";
args = [{ name: "name", required: true }];
options = [{ flag: "-l, --lastName <lastName>" }];
run(name: string, { lastName }?: { lastName: string }): void {
console.log(`Hello ${name}!`);
return;
}
}
Options
description
- Type:
string
- Default:
undefined
args
- Type:
[{ name: string; description: string; required: boolean }]
- Default:
undefined
options
- Type:
[{ flag: string; description: string; defaultValue: string | boolean; choices?: string[] }]
- Default:
undefined
isDefault
- Type:
boolean
- Default:
false
Don't forget about the bin property in the package.json file. When you publish your library you will be able to call it via myLib
{
"name": "my-lib",
"version": "1.0.0",
"main": "./index.js",
"bin": {
"myLib": "./index.js"
}
}
Compiling
Compile your code with numen
numen watch
Run node lib
After publishing just myLib
node lib
Usage: mylib [options] [command]
Options:
-v, --version output the version number
-h, --help display help for command
Commands:
commandName1 <name> My first command
help [command] display help for command
node lib commandName1 World
Hello World!