Skip to content

Instantly share code, notes, and snippets.

@ask-compu
Last active June 28, 2017 05:05
Show Gist options
  • Save ask-compu/850c1ab00a41e667b7cdeb8f2da9b426 to your computer and use it in GitHub Desktop.
Save ask-compu/850c1ab00a41e667b7cdeb8f2da9b426 to your computer and use it in GitHub Desktop.
import sys
def command1(option1="Undefined", option2="Undefined"):
print("This is command1 with " + option1 + " and " + option2)
def command2(option1="Undefined", option2="Undefined"):
print("This is command2 with " + option1 + " and " + option2)
commands = {'cmd1': command1, 'cmd2': command2}
while True:
userInputraw=str(input("Please input a Command: "))
if userInputraw:
userInput=userInputraw.split(" ")
if userInput[0]=="quit":
print("Bye!")
sys.exit()
elif userInput[0] in commands:
try:
commands[userInput[0]](*userInput[1:])
except TypeError:
print("That was too many command options, try again")
continue
else:
print("Not a valid command")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment