From: W. Trevor King Date: Wed, 6 Feb 2013 21:02:12 +0000 (-0500) Subject: cli: Add --select to filter the stack by index X-Git-Tag: v0.1~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=29f2ea1de50b459406f8acc506b34bf954c47af5;p=quizzer.git cli: Add --select to filter the stack by index For example, you can show the questions in a quiz with either the `config` tag or the `checkout` tag: $ ./pq.py --all --tag config --tag checkout --questions quizzes/git.json Question 0: Configure your user-wide name to be `A U Thor`. Question 1: Configure your user-wide email to be `author@example.com`. Question 2: You've messed up your README file. Restore it to the last committed version. Say questions 0 and 2 look interesting, and you'd like to try question 2 first. Run: $ ./pq.py --all --tag config --tag checkout -s 2 -s 0 quizzes/git.json --- diff --git a/quizzer/cli.py b/quizzer/cli.py index 89d972f..d61f815 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( + '-s', '--select', action='append', type=int, + help='select questions from the original stack by index') 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') @@ -74,6 +77,8 @@ def main(): for tag in sorted(tags): print(tag) return + if args.select: + stack = [stack[i] for i in args.select] if args.questions: for i,q in enumerate(stack): print('Question {}:'.format(i))