I received some input from @gregcaporaso and my code is based heavily on the implementation of optparse so I am listing him here as well.