help un solely unrecognised options

This commit is contained in:
Mattias Andrée 2012-10-22 14:58:55 +02:00
parent f6eae560b1
commit b160350c0d

View file

@ -150,8 +150,10 @@ class Ponysay():
self.quote(args) self.quote(args)
if warn: if warn:
printerr('-q cannot be used at the same time as -f or -F.') printerr('-q cannot be used at the same time as -f or -F.')
else: elif not unrecognised:
self.print_pony(args) self.print_pony(args)
else:
args.help()
############################################## ##############################################
@ -1091,7 +1093,8 @@ class ArgParser():
''' '''
Parse arguments Parse arguments
@param args:list<str> The command line arguments, should include the execute file at index 0, `sys.argv` is default @param args:list<str> The command line arguments, should include the execute file at index 0, `sys.argv` is default
@return :bool Whether no unrecognised option is used
''' '''
def parse(self, argv = sys.argv): def parse(self, argv = sys.argv):
self.argcount = len(argv) - 1 self.argcount = len(argv) - 1
@ -1107,9 +1110,11 @@ class ArgParser():
tmpdashed = False tmpdashed = False
get = 0 get = 0
dontget = 0 dontget = 0
self.rc = True
def unrecognised(arg): def unrecognised(arg):
sys.stderr.write('%s: warning: unrecognised option %s\n' % (self.__program, arg)) sys.stderr.write('%s: warning: unrecognised option %s\n' % (self.__program, arg))
self.rc = False
while len(deque) != 0: while len(deque) != 0:
arg = deque[0] arg = deque[0]
@ -1203,6 +1208,8 @@ class ArgParser():
self.message = ' '.join(self.files) if len(self.files) > 0 else None self.message = ' '.join(self.files) if len(self.files) > 0 else None
return self.rc
''' '''
Prints a colourful help message Prints a colourful help message
@ -2008,7 +2015,7 @@ class SpelloCorrecter(): # Naïvely and quickly proted and adapted from optimise
m0[x] = x m0[x] = x
x -= 1 x -= 1
previous = "" previous = ''
self.dictionary[-1] = previous; self.dictionary[-1] = previous;
for directory in directories: for directory in directories:
@ -2354,7 +2361,10 @@ opts.add_variadic( ['--f', '--files', '--ponies'], arg = 'PONY')
opts.add_variadic( ['--F', '++files', '++ponies'], arg = 'PONY') opts.add_variadic( ['--F', '++files', '++ponies'], arg = 'PONY')
opts.add_variadic( ['--q', '--quotes'], arg = 'PONY') opts.add_variadic( ['--q', '--quotes'], arg = 'PONY')
opts.parse() '''
Whether at least one unrecognised option was used
'''
unrecognised = not opts.parse()