I am trying to verify the validity of a string to ensure that it is a legal command I can pass to the terminal. If the string passes the test, I return True. Otherwise, I return False and an error message.
My code is pretty ugly with lots of nested if statements - how can I improve it?
task = task.split()
if len(task) > 1:
if task[0] == 'svn':
if task[1] in ALLOWED:
if len(task[2:]) == ALLOWED[task[1]]:
return True, task, None
else:
return False, "Incorrect number of arguments."
else:
return False, "Not a legal command."
else:
return False, "Not a subversion command."
else:
return False, "Invalid input"
subprocessmodule. And rather than returning a bool, you probably want to raise an exception.