title: Allowing specific values for an Argparse argument
body: <p>Is it possible to require that an <a href="https://docs.python.org/library/argparse.html" rel="noreferrer"><code>argparse</code></a> argument be one of a few preset values?</p>
  
  <p>My current approach would be to examine the argument manually and if it's not one of the allowed values call <a href="https://docs.python.org/library/argparse.html#argparse.ArgumentParser.print_help" rel="noreferrer"><code>print_help()</code></a> and exit.</p>
  
  <p>Here's the current implementation:</p>
  
  <pre><code>...
  parser.add_argument('--val',
                      help='Special testing value')
  
  args = parser.parse_args(sys.argv[1:])
  if args.val not in ['a', 'b', 'c']:
      parser.print_help()
      sys.exit(1)
  </code></pre>
  
  <p>It's not that this is particularly difficult, but rather that it appears to be messy.</p>