docopt / docopt.go

A command-line arguments parser that will make you smile.
http://docopt.org/
MIT License
1.43k stars 111 forks source link

-vvv looks broken #52

Closed fenollp closed 6 years ago

fenollp commented 6 years ago

Hi. After the merge of the big rewrite about a week ago it seems that [-vvv] handling is broken. Before, something along

Options:
  mybin [-vvv] act

With args[“-v”].(int) would take values from 0 to 3 for the inputs:

Now with the new parser and the new API args.Int(“-v”) gives a value of 0 and an error along the lines of “this is uncastable” for any amount of Vs.

I will work on creating a minimal example that uses both APIs tomorrow. I don’t remember that I found this usage in the golang examples/tests.

But then I am maybe just misusing the newer api. What do you think? cc @aviddiviner

fenollp commented 6 years ago

Note: this is saying that #36 was half solved, at least before the rewrite.

fenollp commented 6 years ago

Ah! args.Int("-v") failed with key: "-v" failed type conversion because it's already an int! Solved it by just using args["-v"].(int).

Maybe opts.go Int,Float64 funcs could have a case that checks reflect.TypeOf before attempting strconv? I can make that PR if you'd like.

Anyhow, this is more of feature request than a bugfix. Issue solved.