title: python argparse with dependencies
body: <p>I'm writing a script which has 2 arguments which are mutually exclusive, and an option that only makes sense with one of those arguments. I'm trying to set up argparse to fail if you call it with the argument that makes no sense.</p>
  
  <p>To be clear:</p>
  
  <p><code>-m -f</code> makes sense</p>
  
  <p><code>-s</code> makes sense</p>
  
  <p><code>-s -f</code> should throw errors</p>
  
  <p>no arguments are fine.</p>
  
  <p>The code I have is:</p>
  
  <pre><code>parser = argparse.ArgumentParser(description='Lookup servers by ip address from host file')
  parser.add_argument('host', nargs=1,
              help="ip address to lookup")
  main_group = parser.add_mutually_exclusive_group()
  mysql_group = main_group.add_argument_group()
  main_group.add_argument("-s", "--ssh", dest='ssh', action='store_true',
              default=False,
              help='Connect to this machine via ssh, instead of printing hostname')
  mysql_group.add_argument("-m", "--mysql", dest='mysql', action='store_true',
              default=False,
              help='Start a mysql tunnel to the host, instead of printing hostname')
  mysql_group.add_argument("-f", "--firefox", dest='firefox', action='store_true',
              default=False,
              help='Start a firefox session to the remotemyadmin instance')
  </code></pre>
  
  <p>Which doesn't work, as it spits out</p>
  
  <pre><code> usage: whichboom [-h] [-s] [-m] [-f] host
  </code></pre>
  
  <p>rather than what I'd expect:</p>
  
  <pre><code> usage: whichboom [-h] [-s | [-h] [-s]] host
  </code></pre>
  
  <p>or somesuch.</p>
  
  <pre><code> whichboom -s -f -m 116
  </code></pre>
  
  <p>also doesn't throw any errors.</p>