Fix bug in cli argument parsing

The argument list was being manipulated inside the for loop.
This was causing the loop to behave very strangely on some systems.
The loop would exit after the first iteration and the command would
exit with an error