Skip to content

Instantly share code, notes, and snippets.

@baldwint
Created September 8, 2012 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baldwint/3672842 to your computer and use it in GitHub Desktop.
Save baldwint/3672842 to your computer and use it in GitHub Desktop.
globaloptions bug in optster
#!/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