From 29f2ea1de50b459406f8acc506b34bf954c47af5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 6 Feb 2013 16:02:12 -0500 Subject: [PATCH] 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 --- quizzer/cli.py | 5 +++++ 1 file changed, 5 insertions(+) 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)) -- 2.26.2