title: Restricting values of command line options
body: <p>How do I restrict the values of the argparse options?</p>
  
  <p>In the below code <code>sau</code> option should only accept a number of <code>0</code> or <code>1</code> and <code>bg</code> should only allow an integer. How can I implement this?</p>
  
  <pre><code>import os
  import sys, getopt
  import argparse
  
  def main ():
      parser = argparse.ArgumentParser(description='Test script')
      parser.add_argument('-sau','--set',action='store',dest='set',help='&lt;Required&gt; Set flag',required=True)
      parser.add_argument('-bg','--base_g',action='store',dest='base_g',help='&lt;Required&gt; Base g',required=True)
      results = parser.parse_args() # collect cmd line args
      set = results.set
      base_g = results.base_g
  
  if __name__ == '__main__':
      main()
  </code></pre>