Extract common command line parser code

The command line parser uses the same code in three places, appending a
word to the array of arguments. This might be prone to errors so we
should refactor it into a separate function and instead call that
function when needed.

Signed-off-by: Marcus Karlsson <mk@acc.umu.se>