Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parseopt parsing ? #9619

Closed
fenekku opened this issue Nov 4, 2018 · 8 comments

Comments

Projects
None yet
4 participants
@fenekku
Copy link
Contributor

commented Nov 4, 2018

The parseopt module (only tested with new one) does not take `""`` as option value, leading to unexpected parsing. I think this is undesirable, but maybe you think not.

Example

# testParsing.nim
import parseopt

for kind, key, val in parseopt.getopt():
  case kind
  of cmdArgument:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdLongOption, cmdShortOption:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdEnd: assert(false) # cannot happen

On the command line:

./testParsing --option="" --anotherOption tree

Current Output

kind: cmdLongOption key: option val: --anotherOption
kind: cmdArgument key: tree val: 

Expected Output

kind: cmdLongOption key: option val: 
kind: cmdLongOption key: --anotherOption val:
kind: cmdArgument key: tree val: 

Additional Information

This was run on fish shell.

Also:

var p = initOptParser("""--option="" --anotherOption tree""")
for kind, key, val in p.getopt():
  case kind
  of cmdArgument:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdLongOption, cmdShortOption:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdEnd: assert(false) # cannot happen

outputs:

kind: cmdLongOption key: option val: ""
kind: cmdLongOption key: --anotherOption val:
kind: cmdArgument key: tree val: 
@krux02

This comment has been minimized.

Copy link
Contributor

commented Nov 4, 2018

@Araq what is the status on parseopt? Remind me if I misremember, but didn't you mention that there was a new parseopt that was more correct?

@Araq

This comment has been minimized.

Copy link
Member

commented Nov 5, 2018

I fixed ours, it's correct afaict:

import parseopt

var p = initOptParser(@["--option=", "", "--anotherOption", "tree"])
for kind, key, val in p.getopt():
  case kind
  of cmdArgument:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdLongOption, cmdShortOption:
    echo "kind: ", kind, " key: ", key, " val: ", val
  of cmdEnd: assert(false)

Produces the correct results for me here on Windows.

@krux02

This comment has been minimized.

Copy link
Contributor

commented Nov 5, 2018

I see an empty argument. In bash (and other shells), the command line ./testParsing --option="" --anotherOption tree is split in these arguments: "--option=" "--anotherOption" "tree". --option="" is a concatenation of "--option=" and "", which is the same as just "--option="

@dom96

This comment has been minimized.

Copy link
Member

commented Nov 5, 2018

I've already mentioned this to Araq but I suppose I should post this publicly too: new parseopt behaviour broke Aporia :(

screen shot 2018-11-05 at 20 45 42

(Yep, I still use it).

@dom96 dom96 added the Stdlib label Nov 5, 2018

@krux02

This comment has been minimized.

Copy link
Contributor

commented Nov 5, 2018

@dom96 I can't even build aporia anymore, and that has nothing to do with optparsing.

@krux02 krux02 self-assigned this Nov 6, 2018

@Araq Araq closed this in c0fc2f5 Nov 9, 2018

@dom96

This comment has been minimized.

Copy link
Member

commented Nov 9, 2018

@krux02 that doesn't matter. The Nim parsing behaviour changed. I've been running the same version of Aporia for years.

@krux02

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2018

@dom96 it does matter. When I can't built aporia I can't test if Aporia still runs with the changes of parseopt.

@dom96

This comment has been minimized.

Copy link
Member

commented Dec 19, 2018

@krux02 this is where choosenim comes in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.