Getopt for commandline argument parsing

This seems to be used in one function only. Can we move it to that function and remove the getopt include from this file?