From: W. Trevor King Date: Wed, 6 Feb 2013 14:59:11 +0000 (-0500) Subject: cli: Add the --tags option to list tags on the stack X-Git-Tag: v0.1~28 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a27c0e75e7e96f1a29c63e1dcee744ed0b333b4d;p=quizzer.git cli: Add the --tags option to list tags on the stack --- diff --git a/quizzer/cli.py b/quizzer/cli.py index 4df0b15..e40332f 100644 --- a/quizzer/cli.py +++ b/quizzer/cli.py @@ -41,6 +41,9 @@ def main(): parser.add_argument( '-t', '--tag', action='append', help='limit original questions to those matching at least one tag') + parser.add_argument( + '--tags', action='store_const', const=True, default=False, + help='instead of running the quiz, print a list of tags on the stack') parser.add_argument( 'quiz', metavar='QUIZ', help='path to a quiz file') @@ -60,6 +63,13 @@ def main(): stack = [question for question in quiz] if args.tag: stack = [q for q in stack if q.tags.intersection(args.tag)] + if args.tags: + tags = set() + for q in stack: + tags.update(q.tags) + for tag in sorted(tags): + print(tag) + return ui = _cli.CommandLineInterface(quiz=quiz, answers=answers, stack=stack) ui.run() ui.answers.save()