From f46662bc16be9cd7001421c007c514d75f8aa961 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Fri, 18 Jan 2019 23:05:02 +0000 Subject: [PATCH] Add check before trying to second character of token --- pymacro/pymacro | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pymacro/pymacro b/pymacro/pymacro index af88c30..0033342 100755 --- a/pymacro/pymacro +++ b/pymacro/pymacro @@ -11,8 +11,6 @@ def get_args(): parser = argparse.ArgumentParser() parser.add_argument("-m", "--macros", default=["macros"], action="append", help="Extra files where macros are stored") - parser.add_argument("-s", "--silent", default=False, action="store_true", - help="Do not print processed file") parser.add_argument("input", help="The file to be processed") parser.add_argument("output", help="The location of the output") return parser.parse_args() @@ -58,7 +56,6 @@ def pluralize(word, macro=None): def upper_check(token, word): - lowercase = False all_caps = True for letter in token: @@ -69,8 +66,9 @@ def upper_check(token, word): if all_caps: return word.upper() - if token[1].isupper(): - return word[:1].upper() + word[1:] + if len(token) > 1: + if token[1].isupper(): + return word[:1].upper() + word[1:] return word @@ -166,9 +164,6 @@ def main(args): with open(args.output, 'w+') as file: file.write(output) - if not args.silent: - print(output) - return 0