# CMDLine
CMDLine Allows you to define nodejs command line tools. It works by sing a folder structure and lets you call generator function (async if using babel), normal function and also function that return promises. When runnig in the target folder it will try to load all the files under the /target/commands/ so your final users can easily extend your cli tool.
Installation
npm install cmd-line -S
Usage
/* /mycommand */#!/usr/bin/env nodeconst CMD = default;const cmdtest = 'mycommand';let promise = cmdtest ;
Definign a Command
/* /commands/subcmd1.js */exportsdefault = cmd: __filename args: 'arg1' '?arg2' options: '-f''--force' 'Override it!' '--port''--port comport com4' 'Select your COMPort.' description: 'My awsome command' { return 1; };
mycommand subcmd1 arg1 -f
- cmd[ string ]: The name of the command that will be reconigzed.
- args[ array(string) ]: Argumments that will be passed to the command, by placing "?" before a command you make it optional.
- options[ array(array(string)) ]: The options that the program will receive.
- option[ array(string) ].
- First value: Is the short tag.
- Second value: Is the tag. It can have a variable receiver and a defvalue. Tag must be prepend with "--" varname and defvalue a separeted by " ".
- Third value: Is tehe description of the option.
Automatic Help
By default a -h | --help option is added and it will generete an automatic text.
mycommand subcmd1mycommand subcmd1 -h
Outputs:
mycommand subcmd1 arg1 ?arg2 [options]
My awsome command
-h --help Show the help for this command
-f --force Override it!
--port comport Select your COMPort.
Customizing Help
If you need it you can change the template for the help like this:
/* /mycommand */// ...cmdtest arguments args options { let shortag tag variable description = option; return ` `; }
The argumments and the options have a serializer, you can change it this way
/* /mycommand */// ...cmdtest arguments args // longest is the space used by the tag and the shortag // varlen is the space used by the varname options { let shortag tag variable description = option; return ` `; }
Customizing help by command
Another option is to custumaize only one command help.
/* /commands/subcmd2.js */const Command = default; exportsdefault = __filename 'Hola Mundo' ;};
mycommad subcmd2 -h Outputs:My Custom Help