Skip to content

Arguments of negative numbers #413

Closed

Description

@ciceropablo

It makes sense?

$ node index.js 1 2 3
# [ '1', '2', '3' ]

$ node index.js 1 -2 3
# [ '1' ]

Activity

  1. SomeKittens commented on Jun 19, 2015

    @SomeKittens
    Collaborator

    In this case you'd use the double hyphen -- to end option parsing.

  2. ciceropablo commented on Jun 19, 2015

    @ciceropablo
    ContributorAuthor

    Ok!
    Documentation about it (literal args)?

  3. SomeKittens commented on Jun 19, 2015

    @SomeKittens
    Collaborator

    That's a general CLI thing not specific to commander

  4. sjlongland commented on Feb 23, 2021

    @sjlongland

    Hi,

    Just stumbled on this today… Would it not be better for the code to first check that there exists at least one purely numeric argument defined for the action or globally, before assuming that the - parameter is in fact an option?

    In my case, it's a option to an "action" which is getting confused:

    program
        .command('readloadsurvey <num> [start] [end]')
        .description('read load survey <num> starting at record <start>')
        .option('--search-ts', 'Search by time-stamp')
        .action((num, start, end, options) => {
            /* … etc… */
        });

    Here, there is no option that matches the regex ^-\d$; therefore, an option like -1 cannot be anything but a negative number. In fact, there isn't even any "short form" arguments defined anywhere, so it'd be nice to be able to disable this, as the "feature" if possible. I can see it being ambiguous if I had defined any options matching this form, but here, that is not the case so it'd be better to assume "this is a number" rather than "this is an option".

  5. shadowspawn commented on Feb 23, 2021

    @shadowspawn
    Collaborator

    Commander does not currently treat numbers as special. It is a little appealing, but this has not come up very often and would be a special case in the quite complicated parsing, so my first reaction is unlikely.

    If you are interested in gathering more feedback, please open a new issue.

    Related: #61

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions