我只是想将一个值作为字符串作为必填字段传递
import commander from 'commander';
const split = (str: string) => {
return str.split(',')
};
export const cli = () => {
commander
.version('0.0.1')
.option('-q --query <value>', `Add query example: -q #javascript`, '#javascript')
.option('-s --min [n]', `Add min amount of time to wait before each action example: -s 2500`, 2500)
.option('-l --max [n]', `Add max amount of time to wait before each action example: -l 240000`, 240000)
.option('-d --duration [n]', `Duration in hours example: -d 24`, 1)
.option('-a --actions <list>', `Actions to use example: -a like, follow`, split, [])
.parse(process.argv)
.on('error', () => {
commander.outputHelp();
process.exit();
});
return commander;
}
我在跑
$ ts-node ./index.ts -q #java -s 2403 -l 240001 -d 2 -a follow,like
/*
starting tweety bot
error: option `-q --query <value>' argument missing
*/
我提供了价值,但仍然抛出。如果我更改为非必填字段,它只会返回 defaultValue 而不是传递。