Created
September 8, 2012 08:47
-
-
Save baldwint/3672842 to your computer and use it in GitHub Desktop.
globaloptions bug in optster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Demonstrates a bug in opster. | |
This is intended to have two subcommands, `edit` and `read`. | |
`read` takes a positional argument, `edit` takes none. | |
If you run the script as-is, like:: | |
python bug.py edit | |
or:: | |
python bug.py read somepage | |
you should see things working. However, if you switch the | |
line commented out at the bottom (which is intended to add | |
optional username/password parameters to each command), | |
neither of these will work - they quit out due to 'invalid | |
arguments'. | |
That is, adding two options globally makes previously valid | |
arguments invalid. I don't think this is the intended | |
behavior. | |
""" | |
import opster | |
options = [('u', 'username', '', "your username."), | |
('p', 'password', '', "your login password.")] | |
@opster.command() | |
def edit(): | |
"""Edit your page.""" | |
print 'editing your page' | |
@opster.command() | |
def read(page): | |
"""Read another user's page.""" | |
print 'reading', page | |
if __name__ == "__main__": | |
opster.dispatch() # this works | |
#opster.dispatch(globaloptions = options) # this doesn't. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment