|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Author : Ryan Campbell <me@ryancampbell.name> |
| 4 | +Date : 2023-09-25 |
| 5 | +Purpose: Picnic game |
| 6 | +""" |
| 7 | + |
| 8 | +import argparse |
| 9 | + |
| 10 | + |
| 11 | +# -------------------------------------------------- |
| 12 | +def get_args(): |
| 13 | + """Get command-line arguments""" |
| 14 | + |
| 15 | + parser = argparse.ArgumentParser( |
| 16 | + description="Picnic game", |
| 17 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 18 | + ) |
| 19 | + |
| 20 | + parser.add_argument("items", metavar="str", help="Item(s) to bring", nargs="+") |
| 21 | + |
| 22 | + parser.add_argument("-s", "--sorted", help="Sort the items", action="store_true") |
| 23 | + |
| 24 | + return parser.parse_args() |
| 25 | + |
| 26 | + |
| 27 | +# -------------------------------------------------- |
| 28 | +def main(): |
| 29 | + """Make a jazz noise here""" |
| 30 | + |
| 31 | + args = get_args() |
| 32 | + |
| 33 | + if len(args.items) == 1: |
| 34 | + print(f"You are bringing {args.items[0]}.") |
| 35 | + elif len(args.items) == 2: |
| 36 | + if args.sorted: |
| 37 | + args.items.sort() |
| 38 | + print(f"You are bringing {' and '.join(args.items)}.") |
| 39 | + else: |
| 40 | + if args.sorted: |
| 41 | + args.items.sort() |
| 42 | + last_item = args.items.pop() |
| 43 | + print(f"You are bringing {', '.join(args.items)}, and {last_item}.") |
| 44 | + |
| 45 | + |
| 46 | +# TODO |
| 47 | +# Add an option so the user can choose not to print with the Oxford comma (even though that is a morally indefensible option). |
| 48 | +# Add an option to separate items with a character passed in by the user (like a semicolon if the list of items needs to contain commas). |
| 49 | + |
| 50 | +# -------------------------------------------------- |
| 51 | +if __name__ == "__main__": |
| 52 | + main() |
0 commit comments