From f6eae560b122fd76b12655bf53eb6a4efb9533ac Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 22 Oct 2012 14:40:20 +0200 Subject: -q works as -f + added --f, --F and --q which are varidic variants of -f, -F and -q, respectivly + warn if -q is used with -f and -F but allow (but still warn if used) `-q -f` --- ponysay.py | 55 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) (limited to 'ponysay.py') diff --git a/ponysay.py b/ponysay.py index b7abe7f..a46576c 100755 --- a/ponysay.py +++ b/ponysay.py @@ -47,6 +47,14 @@ programs by default, report them to Princess Celestia so she can banish them to def print(text = '', end = '\n'): sys.stdout.buffer.write((str(text) + end).encode('utf-8')) +''' +stderr equivalent to print() + +@param text:str The text to print (empty string is default) +@param end:str The appendix to the text to print (line breaking is default) +''' +def printerr(text = '', end = '\n'): + sys.stderr.buffer.write((str(text) + end).encode('utf-8')) ''' Checks whether a text ends with a specific text, but has more @@ -82,18 +90,23 @@ class Ponysay(): global extraponydirs ## Emulate termial capabilities - if args.opts['-X'] is not None: - linuxvt = False - usekms = False - elif args.opts['-V'] is not None: - linuxvt = True - usekms = False - elif args.opts['-K'] is not None: - linuxvt = True - usekms = True + if args.opts['-X'] is not None: (linuxvt, usekms) = (False, False) + elif args.opts['-V'] is not None: (linuxvt, usekms) = (True, False) + elif args.opts['-K'] is not None: (linuxvt, usekms) = (True, True) ponydirs = vtponydirs if linuxvt and not usekms else xponydirs extraponydirs = extravtponydirs if linuxvt and not usekms else extraxponydirs + ## Variadic variants of -f, -F and -q + if args.opts['--f'] is not None: + if args.opts['-f'] is not None: args.opts['-f'] += args.opts['--f'] + else: args.opts['-f'] = args.opts['--f'] + if args.opts['--F'] is not None: + if args.opts['-F'] is not None: args.opts['-F'] += args.opts['--F'] + else: args.opts['-F'] = args.opts['--F'] + if args.opts['--q'] is not None: + if args.opts['-q'] is not None: args.opts['-q'] += args.opts['--q'] + else: args.opts['-q'] = args.opts['--q'] + ## Run modes if args.opts['-h'] is not None: args.help() elif args.opts['--quoters'] is not None: self.quoters() @@ -126,8 +139,19 @@ class Ponysay(): mode += '$/= $$\\= $' ## The stuff - if args.opts['-q'] is not None: self.quote(args) - else: self.print_pony(args) + if args.opts['-q'] is not None: + warn = (args.opts['-f'] is not None) or (args.opts['-F'] is not None) + if (len(args.opts['-q']) == 1) and ((args.opts['-q'][0] == '-f') or (args.opts['-q'][0] == '-F')): + warn = True + if args.opts['-q'][0] == '-f': + args.opts['-q'] = args.files + if args.opts['-f'] is not None: + args.opts['-q'] += args.opts['-f'] + self.quote(args) + if warn: + printerr('-q cannot be used at the same time as -f or -F.') + else: + self.print_pony(args) ############################################## @@ -2270,8 +2294,8 @@ usage_saythink = '\033[34;1m(ponysay | ponythink)\033[21;39m' usage_common = '[-c] [-W\033[4mCOLUMN\033[24m] [-b\033[4mSTYLE\033[24m]' usage_listhelp = '(-l | -L | -B | +l | +L | -v | -h)' usage_file = '[-f\033[4mPONY\033[24m]* [[--] \033[4mmessage\033[24m]' -usage_xfile = '[-F\033[4mPONY\033[24m]* [[--] \033[4mmessage\033[24m]' -usage_quote = '-q [\033[4mPONY\033[24m*]' +usage_xfile = '(-F\033[4mPONY\033[24m)* [[--] \033[4mmessage\033[24m]' +usage_quote = '(-q \033[4mPONY\033[24m)*' usage = '%s %s\n%s %s %s\n%s %s %s\n%s %s %s' % (usage_saythink, usage_listhelp, usage_saythink, usage_common, usage_file, @@ -2325,7 +2349,10 @@ opts.add_argumented( ['-W', '--wrap'], arg = 'COLUMN', help = opts.add_argumented( ['-b', '--bubble', '--balloon'], arg = 'STYLE', help = 'Select a balloon style.') opts.add_argumented( ['-f', '--file', '--pony'], arg = 'PONY', help = 'Select a pony.\nEither a file name or a pony name.') opts.add_argumented( ['-F', '++file', '++pony'], arg = 'PONY', help = 'Select a non-MLP:FiM pony.') -opts.add_variadic( ['-q', '--quote'], arg = 'PONY', help = 'Select a ponies which will quote themself.') +opts.add_argumented( ['-q', '--quote'], arg = 'PONY', help = 'Select a pony which will quote herself.') +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() -- cgit