0.0.14 • Published 11 years ago
clitoolkit v0.0.14
clitookit
The command line toolkit
###Installation
npm install clitoolkit###Quick Start
File /bin/test:
#!/usr/bin/env node
var clitoolkit = require('clitoolkit');
//initial other command line tools
clitoolkit.init({
version: 1.0.1,
plugin: [
'clitoolkit-plugin-a',
'clitoolkit-plugin-b'
]
}, process.argv);Plugin clitoolkit-plugin-a(clitoolkit-plugin-a/main.js):
module.exports = function(PluginAPI){
PluginAPI.register('a', 'command a description', [{
sample: '-d, --dest <names>',
desc: 'dest files',
defVal: 'dest'
}, {
sample: '-c, --config <names>',
desc: 'set config file',
}], function(commander, progArg){
console.log('command a running...');
});
};Plugin clitoolkit-plugin-b(clitoolkit-plugin-b/main.js):
module.exports = function(PluginAPI){
PluginAPI.register('b', 'command b description', [{
sample: '-o, --ok <names>',
desc: 'OK!!!'
}, {
sample: '-i, --info <names>',
desc: 'command info',
}], function(commander, progArg){
console.log('command b running...');
});
};Execute the command /bin/test:
#show the usage of command test
test --help
#show the usage of command a
test a --help
#execute the command a
test a -d -c
#show the usage of command b
test b --help
#execute the command b
test b -oi###Init API Options
opt:type-> Objectthe configrationversion:type-> Stringthe command versionpluginBase(optional):type-> Stringthe plugin root pathplugin:type-> Arraythe clitoolkit plugins. if can not find the plugin in pluginBase clitoolkit will find node_modules which have the same name with the target plugin.
proArgv:type-> Arraythe progress's arguments(process.argv)
###Plugin
- create a plugin for extend the command
- plugin is a folder contains a
main.js main.jsshould exports a function that with a PluginAPI arguments- you can use PluginAPI to register a new command
Example:
module.exports = function(PluginAPI){
PluginAPI.register(cmd, desc, options, action);
};####PluginAPI
#####register(name, desc, option, action)
name:type-> Stringcommand namedesc:type-> Stringdescriptionoption:type-> Arraycommand optionssample:type-> Stringcommand sample, e.g.: '-d, --dest 'desc(optional):type-> Stringoption descriptiondefVal(optional):type-> anythe default value
action:type-> functioneval this function when the command trigger