Parses options to command-line programs, similar to how getopt works.