The program I am working atm has a terminal-style interface. I have a block of code that checks for the input with a custom library I made :
try:
rawcmd = typing_.typingInput('> ').split() # Splits the command into 2 parts.
try:
global cmd
cmd = rawcmd[0]
except IndexError:
cmd = ' '
and then that leads into a large ladder of if elif statements (I'll only provide a few):
if cmd == '?' or cmd =='help': # Lists out all the commands and what each one does.
# Just some filler code here
elif cmd == 'ls': # Lists out the Current Working Directory, aswell as all the files within that directory.
typing_.typingPrint('Current Working Directory: ' +os.getcwd()+'\n')
delimiter = '\n'
files = delimiter.join(os.listdir())
typing_.typingPrint(files+'\n')
elif cmd == 'cd': # Changes the directory to the supplied one
try:
path = os.path.abspath(rawcmd[1])
os.chdir(path)
except FileNotFoundError:
typing_.typingPrint('No Directory with that name')
elif cmd == 'mkdir': # Creates a new Folder in the file system.
name=rawcmd[1]
os.mkdir(name)
elif cmd == 'mkfile': # Runs the CreateFile() function
name = rawcmd[1]
createFile(name)
elif cmd == 'rmvfile': # Runs the DeleteFile() function
name = rawcmd[1]
deleteFile(name)
elif cmd == 'editfile': # Runs the EditFile() function
name = rawcmd[1]
editFile(name)
elif cmd == 'readfile': # Runs the ReadFile() function
name = rawcmd[1]
viewFile(name)
elif cmd == 'rmvtree': # Deletes the supplied folder and all files within.
name = rawcmd[1]
shutil.rmtree(name)
elif cmd == 'exit': # Quits the Terminal.
Is there a better way to do this that would be more efficient, and easier for other people to read?