{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"user":{"avatar_url":"https://secure.gravatar.com/avatar/664d320baa05c827ff08ed361fe77769?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"664d320baa05c827ff08ed361fe77769","url":"https://api.github.com/users/oscarbenjamin","login":"oscarbenjamin","id":1159732},"milestone":null,"updated_at":"2011-10-29T23:03:46Z","labels":[],"assignee":null,"comments":0,"closed_at":null,"url":"https://api.github.com/repos/piranha/opster/issues/3","body":"Hi again.\r\n\r\nI've found that opster generates nice helpful message for the user when an option argument is missing or is not a valid a=b string for dict options, but bombs with a stcktrace if it fails to parse a float/int option. Example:\r\n\r\nmyscript.py:\r\n\r\n```python\r\nimport sys\r\nimport opster\r\n\r\n@opster.command()\r\ndef main(number=('n', 1, 'integer option'),\r\n         ratio=('r', 1.0, 'float option')):\r\n    print number, ratio\r\n\r\nif __name__ == \"__main__\":\r\n    main(argv=sys.argv[1:])\r\n```\r\n\r\nIf you run `python mtscript.py -n` you get the message\r\n```error: option -n requires argument\r\n\r\nmyscript.py [OPTIONS] \r\n\r\n(no help text available)\r\n\r\noptions:\r\n\r\n -n --number  integer option (default: 1)\r\n -r --ratio   float option (default: 1.0)\r\n -h --help    show help```\r\n\r\nHowever, if you run `python myscript.py -n 1.1` or `python myscript.py -r bad` then you will get something like:\r\n```Traceback (most recent call last):\r\n  File \"myscript.py\", line 10, in <module>\r\n    main(argv=sys.argv[1:])\r\n  File \"/usr/lib/pymodules/python2.7/opster.py\", line 110, in inner\r\n    opts, args = catcher(lambda: parse(argv, options_), func.help)\r\n  File \"/usr/lib/pymodules/python2.7/opster.py\", line 504, in catcher\r\n    return target()\r\n  File \"/usr/lib/pymodules/python2.7/opster.py\", line 110, in <lambda>\r\n    opts, args = catcher(lambda: parse(argv, options_), func.help)\r\n  File \"/usr/lib/pymodules/python2.7/opster.py\", line 371, in parse\r\n    state[name] = t(val)\r\nValueError: invalid literal for int() with base 10: '1.1'```\r\n\r\nThis can be fixed with the following patch (relative to current git master):\r\n\r\n```diff --git a/opster.py b/opster.py\r\nindex c9ec3d8..101ec36 100644\r\n--- a/opster.py\r\n+++ b/opster.py\r\n@@ -439,8 +439,13 @@ def process(args, options, preparse=False):\r\n             state[name][k] = v\r\n         elif t in (types.NoneType, types.BooleanType):\r\n             state[name] = not defmap[name]\r\n-        else:\r\n-            state[name] = t(val)\r\n+        elif t in (int, float):\r\n+            try:\r\n+                state[name] = t(val)\r\n+            except ValueError:\r\n+                raise getopt.GetoptError(\r\n+                    \"invalid option value '%s' for option '%s'\"\r\n+                    % (val, name))\r\n \r\n     for name in funlist:\r\n         state[name] = defmap[name](None)```","html_url":"https://github.com/piranha/opster/issues/3","number":3,"title":"opster bombs with invalid input for float/int option","id":2088800,"created_at":"2011-10-29T23:03:46Z"},"action":"opened"}