mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-29 15:37:59 +01:00
help un solely unrecognised options
This commit is contained in:
parent
f6eae560b1
commit
b160350c0d
1 changed files with 16 additions and 6 deletions
16
ponysay.py
16
ponysay.py
|
@ -150,8 +150,10 @@ class Ponysay():
|
|||
self.quote(args)
|
||||
if warn:
|
||||
printerr('-q cannot be used at the same time as -f or -F.')
|
||||
else:
|
||||
elif not unrecognised:
|
||||
self.print_pony(args)
|
||||
else:
|
||||
args.help()
|
||||
|
||||
|
||||
##############################################
|
||||
|
@ -1092,6 +1094,7 @@ class ArgParser():
|
|||
Parse arguments
|
||||
|
||||
@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):
|
||||
self.argcount = len(argv) - 1
|
||||
|
@ -1107,9 +1110,11 @@ class ArgParser():
|
|||
tmpdashed = False
|
||||
get = 0
|
||||
dontget = 0
|
||||
self.rc = True
|
||||
|
||||
def unrecognised(arg):
|
||||
sys.stderr.write('%s: warning: unrecognised option %s\n' % (self.__program, arg))
|
||||
self.rc = False
|
||||
|
||||
while len(deque) != 0:
|
||||
arg = deque[0]
|
||||
|
@ -1203,6 +1208,8 @@ class ArgParser():
|
|||
|
||||
self.message = ' '.join(self.files) if len(self.files) > 0 else None
|
||||
|
||||
return self.rc
|
||||
|
||||
|
||||
'''
|
||||
Prints a colourful help message
|
||||
|
@ -2008,7 +2015,7 @@ class SpelloCorrecter(): # Naïvely and quickly proted and adapted from optimise
|
|||
m0[x] = x
|
||||
x -= 1
|
||||
|
||||
previous = ""
|
||||
previous = ''
|
||||
self.dictionary[-1] = previous;
|
||||
|
||||
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( ['--q', '--quotes'], arg = 'PONY')
|
||||
|
||||
opts.parse()
|
||||
'''
|
||||
Whether at least one unrecognised option was used
|
||||
'''
|
||||
unrecognised = not opts.parse()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue