climaker
This library is used for creating nice, clean and consistent CLI UI tools in Node.js, with great speed.
Features
- Automated help screen generation for all commands and subcommands
- Automated "Did you mean?" helper on command error
- Automated command-line parameters and argument validation
- Localization support for help content, with default fallback to English
How to use
The following commands will help you get set up:
npm install -g climaker # Create a project with a single binary climaker create myCommand # Add commands to the binary climaker command create newCommandclimaker command create new subCommand # Add a second binary climaker binary create mySecondCommand # Add commands to the second binary climaker command create -b mySecondCommand create newCommandclimaker command create -b mySecondCommand create new subCommand
Manually creating commands
Under the bin/
folder of your package, add a script with
the following content:
#!/usr/bin/env node var path = ;var packageInfo = ; var maker = ;var commandName = 'mytool' ;
Then:
chmod +755 bin/mytoolmkdir /commands
And, finally, under ./commands/index.js
:
exportsdescribe = en: 'My sweet command line' fr: 'Ma commande de ligne sucrée (tee hee)';
And start coding! Add your commands in the ./commands
folder:
// ./commands/create.jsexportsdescribe = en: 'Create a new organization.' ja: '新しい組織を作成する。'; exportsunnamedParams = name: 'something' describe: 'I no bother with localize' allow: true // or int for how many to allow, or false if you want to be strict demand: true // required, set up a count, or false to make optional; exportsparams = name: 'name' demand: true describe: en: 'Name' ja: '名前です' ; // See https://www.npmjs.com/package/yargs#option-key-optexportsoptions = d: alias: 'dest' demand: true f: alias: 'force' describe: 'Force create' boolean: true ; // Options will contain all your options as well as// unnamed parametersexports { console; ;};
You can create sub-folders as well: they will become nested commands.
However, you must make sure to put an index.js
script with the description
of this nested command's subcommand.
For instance, to create the command:
mytool module create myModule --lang=csharp
You would need to create the folder ./commands/module
,
add a description for the module subcommand in ./commands/module/index.js
,
and the nested command itself in ./commands/module/create.js
.
Todo
- Windows testing
- Documentation in Japanese, French, and other languages
- Dictionary feature, to simplify localization of command output
- Autocompletion script generation for Bash, ZSH and PowerShell
-
autocomplete
attribute on options and parameters (specify a command that should return autocompletion data) - Test suite
- Health-check command: check that this project's binaries and commands are complying with how things are supposed to be structured
- Get feedback!
License
MIT.