You can pass formats in an array, by array index order, formats will be used to parse given parameters and callback the first successfully parsed one.
node index.js -h
cliParams.add([
{
params:[
{
param:'input',
type:'string',
alias:'i'
},
{
param:'password',
type:'string',
optional:true,
alias:'p'
}
],
id:'regular'// id is not optional when multiple formats are submitted
},
{
params:{
param:'help',
type:'boolean',
alias:'h'
},
id:'help'// id is not optional when multiple formats are submitted
},
{
params:{
param:'version',
type:'boolean',
alias:'v'
},
id:'version'// id is not optional when multiple formats are submitted
}
]).exec((err,params,id)=>{
if(err)returnconsole.log(err);
console.log(id);
// output: help
console.log(params);
});
{"help":true}
Trailing Param (Target)
Parameter with no name and located at the end of command line will be treated as Target. Every cmd can only have one target and need to be named beforehand.
node index.js -r 50 https://google.com
cliParams.add({
params:
{
param:'rate',
type:'int',
alias:'r'
},
target:{
param:'url',
type:'string',
optional:false// which is default
}
},(err)=>{
if(err)returnconsole.log(err);
cliParams.exec((err,params)=>{
if(err)returnconsole.log(err);
console.log(params);
});
});
{"url":"https://google.com","rate":50}
Array of ...
Passing multiple values with space as separator to a single parameter.