node-js-libs/cli

'string' value_type for options not converted when number is passed

johnkchiu opened this issue · 2 comments

I set a option as 'string':

...
        account: ['a', 'account number', 'string']
...

And this works well in most cases EXCEPT when the value is a number:

$ ./script.js -a 12345

In this case, typeof (options.account) is number. Can you do a covert to String when you do a cli.getValue(...)?

Thanks!

Actually, looks like there's even more problems with 'string' handling. When the value is in int format, it's always getting parsed as int, so the value is getting truncated:

$ ./script.js -a 1312868311701071952
debug: [20223:index.js]  account=1312868311701072000, file=null, max=null

Problem is here - https://github.com/chriso/cli/blob/master/cli.js#L737. It needs to check that 'value_type' is not 'string'.

Looks like that conditional at https://github.com/chriso/cli/blob/master/cli.js#L737 is actually redundant. Commenting it out and testing with:

cli.parse({ 
    astring: ['s', 'an int as a string', 'string'],
    anint:   ['i', 'a (possibly rounded) integer', 'int']
});

and

-s 523465823658273456834632487 -i 6453246587365873568

works fine, because actual ints (as opposed to strings that contain only numbers) are parsed via getInt at https://github.com/chriso/cli/blob/master/cli.js#L757 using a regex.