Use getopt to parse options and add foreground mode.