Unnamed parameter with commander.js

With the present version of commander, it's possible to use positional arguments. See the docs on argument syntax for details, but using your cp example it would be something like:

program
.version('0.0.1')
.arguments('<source> <target>')
.action(function(source, target) {
    // do something with source and target
})
.parse(process.argv);

This program will complain if both arguments are not present, and give an appropriate warning message.


You get all the unnamed parameters through program.args. Add the following line to your example

console.log(' args: %j', program.args);

When you run your app with -p -b -c gouda arg1 arg2 you get

you ordered a pizza with:
- peppers
- bbq
- gouda cheese
args: ["arg1","arg2"]

Then you could write something like

copy args[0] to args[1] // just to give an idea