Last active
September 3, 2019 13:55
-
-
Save szethh/5d0fcd3906764f520e8a2c772b1743ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, shlex | |
def main(): | |
parser = argparse.ArgumentParser('My Command Line Program') | |
parser.add_argument( | |
'--debug', | |
action='store_true', | |
help='Print debug info' | |
) | |
subprasers = parser.add_subparsers(dest='command') | |
create = subprasers.add_parser('create', help='Create a new Game object') | |
create.add_argument('-n', '--name', nargs='+', required=True, help='Name of the game') | |
create.add_argument('-i', '--ID', nargs='+', required=True, help='ID of the game') | |
create.add_argument('-p', '--price', nargs='+', required=True, help='Minimum Price of the game') | |
update = subprasers.add_parser('update', help='Update prices') | |
update.add_argument('-a', '--autobuy', help = 'Wether to autobuy or not.') | |
args = parser.parse_args(arg) | |
if args.debug: | |
print("debug: " + str(args)) | |
if args.command == 'create': | |
print("Created game with name " + str(args.name) + " ID " + str(args.ID) + ", and min price " + str(args.price)) | |
elif args.command == 'update': | |
if not args.autobuy: | |
args.autobuy = False | |
print('Updating. Autobuy is ' + str(args.autobuy)) | |
if __name__ == '__main__': | |
while True: | |
arg = shlex.split(input()) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment