From 68074d113038d99bfca6d1d5000da1da0e633458 Mon Sep 17 00:00:00 2001 From: Kyanos Date: Sun, 28 Feb 2016 23:50:49 -0800 Subject: [PATCH 1/2] Create a common printing function to avoid duplication The various commands differ primarily in the command name and the text printed. Add a method "print_text" to handle most of the formatting, and have the other methods call that. --- src/gitgud/gitgud.py | 57 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/gitgud/gitgud.py b/src/gitgud/gitgud.py index 0199f0e..1e0348b 100644 --- a/src/gitgud/gitgud.py +++ b/src/gitgud/gitgud.py @@ -15,49 +15,46 @@ def parse_args(cmdname): def fig(text): fig = pyfiglet.Figlet() return fig.renderText(text) - + @staticmethod - def gud(): - args = git.parse_args("good") + def print_text(command, format_str, default_qual = ""): + args = git.parse_args(command) name = args.name or "You" sup = args.super - text = "{name} {verb} now {qual} gud!".format(name=name, - verb="is" if args.name else "are", - qual="super" if sup else "so") + if sup: + qual = "super " + else: + if default_qual: + qual = default_qual + else: + qual = "" + + text = format_str.format(name=name, + qual=qual) if sup: text = git.fig(text) print(text) + + @staticmethod + def gud(): + args = git.parse_args("gud") + format_str = "{{name}} {verb} now {{qual}}gud!".format(verb="is" if args.name else "are") + git.print_text(command="gud", + format_str=format_str, + default_qual="so ") @staticmethod def rekt(): - args = git.parse_args("rekt") - name = args.name or "You" - sup = args.super - text = "{name} got {qual}#rekt!".format(name=name, - qual="super " if sup else "") - if sup: - text = git.fig(text) - print(text) + git.print_text(command="rekt", + format_str="{name} got {qual}#rekt!") @staticmethod def spooked(): - args = git.parse_args("spooked") - name = args.name or "You" - sup = args.super - text = "{name} got spooked by a scary skeleton!".format(name=name) - - if sup: - text = git.fig(text) - print(text) + git.print_text(command="spooked", + format_str="{name} got spooked by a scary skeleton!") @staticmethod def job(): - args = git.parse_args("job") - name = args.name or "You" - sup = args.super - text = "{name} got a job in gitting #rekt!".format(name=name) - - if sup: - text = git.fig(text) - print(text) + git.print_text(command="job", + format_str="{name} got a job in gitting #rekt!") From c3acb5b35b885b3954dddcc34e2944ccad8b66ce Mon Sep 17 00:00:00 2001 From: Kyanos Date: Sun, 28 Feb 2016 23:53:01 -0800 Subject: [PATCH 2/2] Add "super" support for "git spooked" and "git job" --- src/gitgud/gitgud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gitgud/gitgud.py b/src/gitgud/gitgud.py index 1e0348b..1f6ac3e 100644 --- a/src/gitgud/gitgud.py +++ b/src/gitgud/gitgud.py @@ -51,10 +51,10 @@ def rekt(): @staticmethod def spooked(): git.print_text(command="spooked", - format_str="{name} got spooked by a scary skeleton!") + format_str="{name} got spooked by a {qual}scary skeleton!") @staticmethod def job(): git.print_text(command="job", - format_str="{name} got a job in gitting #rekt!") + format_str="{name} got a job in gitting {qual}#rekt!")