There is an argparse library I used which does most of these things for you. It's not an interesting exercise to use that. There should be some example in a data tool I wrote.