Skip to content

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

Open

Description

@johnkchiu

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!

Activity

  1. johnkchiu commented on Oct 16, 2014

    @johnkchiu
    Author

    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'.

  2. julianbrowne commented on Jan 5, 2015

    @julianbrowne

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions