question: Add support for list-of-lines help
authorW. Trevor King <wking@tremily.us>
Wed, 6 Feb 2013 17:59:39 +0000 (12:59 -0500)
committerW. Trevor King <wking@tremily.us>
Wed, 6 Feb 2013 17:59:39 +0000 (12:59 -0500)
We use lists of lines for other question attributes (e.g. setup,
teardown, answer, prompt).  Be consistent with multi-line help.

quizzer/question.py
quizzer/ui/cli.py

index 8b2f6dc15dc6ed42e98f0c60f30f20b6bf72df3c..da722df62373c63176490b3a01540ebee0924129 100644 (file)
@@ -74,10 +74,17 @@ class Question (object):
     def check(self, answer):
         return answer == self.answer
 
-    def format_prompt(self, newline='\n'):
-        if isinstance(self.prompt, str):
-            return self.prompt
-        return newline.join(self.prompt)
+    def _format_attribute(self, attribute, newline='\n'):
+        value = getattr(self, attribute)
+        if isinstance(value, str):
+            return value
+        return newline.join(value)
+
+    def format_prompt(self, **kwargs):
+        return self._format_attribute(attribute='prompt', **kwargs)
+
+    def format_help(self, **kwargs):
+        return self._format_attribute(attribute='help', **kwargs)
 
 
 class NormalizedStringQuestion (Question):
index a9bb100e3302ee01940b4da425fd5bc1fb871fcc..064f3081ea1e764b6415fc24f10d5898070ee646 100644 (file)
@@ -43,7 +43,7 @@ class CommandLineInterface (UserInterface):
                 if a in ['?', 'help']:
                     print()
                     print(question.format_prompt())
-                    print(question.help)
+                    print(question.format_help())
                     continue
                 if question.multiline:
                     answers.append(answer)