piranha/opster — Issue #4: wrong name in error for invalid arguments
Author: oscarbenjamin
Created: 2011-10-30 20:35:58+00:00
State: open

Hi again. Thanks for including my patch.

I want to report another issue. This is easiest to explain with an example. Consider the script test.py:

```python
import sys, opster

@opster.command()
def main():
pass

main.command(sys.argv[1:])
```

Now run `python test.py -h` to get:

```none
test.py

(no help text available)

options:

-h --help display help
```

Now run with a positional argument `python test.py arg` to get:

```none
main: invalid arguments

test.py

(no help text available)

options:

-h --help display help
```

So the help names the script as test.py but the error message shows the function name `main`. The script user should not see the function name in this situation. This happens because Dispatcher.command is calling `name_from_python(func.__name__)` which is appropriate for Dispatcher.dispatch but not for Dispatcher.command. The following patch fixes this:

```diff
diff --git a/opster.py b/opster.py
index 026d509..479f1e6 100644
--- a/opster.py
+++ b/opster.py
@@ -118,7 +118,7 @@ class Dispatcher(object):
except TypeError:
options_ = []

- name_ = name or name_from_python(func.__name__)
+ name_ = name or sysname()
if usage is None:
usage_ = guess_usage(func, options_)
else:
```

Patch can also be found at:
http://pastebin.com/rLQMNVKK