Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-3357

Argument parsing could do more to prevent incorrect usage

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: common
    • Labels:
      None

      We recently had a question from a user who ran this command: mongorestore -h 127.0.0.1 -d backup -dir ~/backup/.

      It's very subtle, but there is only one dash before dir. That means this is interpreted as the -d option followed by the string ir, as opposed to -dir (with two dashes).

      There's a couple things that cause problems here:

      1. The argument parsing allows passing the -d option twice, but the last one wins. It would be much better to error out in this case.
      2. Accepting a short option like -d immediately followed by text without a space seems like a recipe for confusing, for exactly the case we see above.

      We can fix this by doing the following:

      1. Error when the same option is provided more than once, except for any option which is explicitly defined as allowing this (if we have any).
      2. Do not allow a short option to be followed by its value without a space.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dave.rolsky@mongodb.com Dave Rolsky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: