Use getopt to parse options and add foreground mode.

This commit also updates the man page with the options.