Is there a way to sum an infinite number of parameters using caporal npm?
var prog = require('caporal');
prog
.version('1.0.0')
.command('sum', 'inputnumber')
.argument('[env...]', 'Other environments')
.action((args) => {
env:[]
console.log(args);
})
prog.parse(process.argv);
This code will print:
./cli sum 1 2 3 4
{ env: [ '1', '2', '3', '4' ] }
How can I split that array and calculate the sum?
I already know how to sum using two defined parameters
var prog = require('caporal');
prog
.version('1.0.0')
.command('sum', 'inputnumber')
.argument('<n1>','first number')
.argument('<n2>','second number')
.action(function(args) {
var result = parseInt(args.n1) + parseInt(args.n2);
console.log(result);
});
prog.parse(process.argv);
./cli sum 1 2
3