Skip to content

Commit

Permalink
option handling made more clear and help output always printed
Browse files Browse the repository at this point in the history
  • Loading branch information
rep committed Dec 15, 2011
1 parent d7bcd17 commit 8cee715
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions cli/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def main(opts, action, pubdata=None):
return 0

def opts():
usage = "usage: %prog -i ident -s secret --host host -p port -c channel1 [-c channel2, ...] <action> [<data>]"
usage = "usage: %prog [options] publish|subscribe <publish_data>"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-c", "--chan",
action="append", dest='channels', nargs=1, type='string',
Expand All @@ -132,9 +132,8 @@ def opts():

options, args = parser.parse_args()

if len(args) < 1:
parser.error('You need to give "subscribe" or "publish" as <action>.')
if args[0] not in ['subscribe', 'publish']:
if len(args) < 1 or args[0] not in ['subscribe', 'publish'] or None in options.__dict__.values():
parser.print_help()
parser.error('You need to give "subscribe" or "publish" as <action>.')

action = args[0]
Expand Down
7 changes: 3 additions & 4 deletions cli/grabfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def main(opts, action, pubdata=None):
return 0

def opts():
usage = "usage: %prog -i ident -s secret --host host -p port -c channel1 [-c channel2, ...] <action> [<data>]"
usage = "usage: %prog [options] publish|subscribe <publish_data>"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-c", "--chan",
action="append", dest='channels', nargs=1, type='string',
Expand All @@ -164,9 +164,8 @@ def opts():

options, args = parser.parse_args()

if len(args) < 1:
parser.error('You need to give "subscribe" or "publish" as <action>.')
if args[0] not in ['subscribe', 'publish']:
if len(args) < 1 or args[0] not in ['subscribe', 'publish'] or None in options.__dict__.values():
parser.print_help()
parser.error('You need to give "subscribe" or "publish" as <action>.')

action = args[0]
Expand Down

0 comments on commit 8cee715

Please sign in to comment.