title: How to Check for and raise an error for no command line argument
body: <p>I have an argparsing program:</p>
  
  <p>import argparse</p>
  
  <pre><code>def main():
      p = argparse.ArgumentParser()
      help_str = {'rule': 'Blah blah blah and stuff.'}
      p.add_argument('-r', '--rule', action="store", type=str, dest='rule', help=help_str['rule'])
      p.set_defaults(rule='string')
      args = p.parse_args()
  </code></pre>
  
  <p>Therefore, my command line input:</p>
  
  <pre><code>username@compname:~$python progname.py -r/--rule 'something'
  </code></pre>
  
  <p>I am trying to figure out how I could just input:</p>
  
  <pre><code>username@compname:~$python progname.py -r/--rule
  </code></pre>
  
  <p>and have my own error message come up:</p>
  
  <pre><code>print '\n    Error: no input value for rule:'
  print '    resetting rule to default value.'
  args.rule = 'string'
  </code></pre>
  
  <p>after this, the rule value should print out as 'string'</p>
  
  <p>I am only slightly fluent in Python, sorry.  I have tried using try/except blocks and even sys.argv[2] (though I may have done something wrong.)  This is the error that keeps popping up with all of my solutions (not very familiar with errors outside Type and Value):</p>
  
  <pre><code>progname.py: error: argument -r/--rule: expected one argument
  </code></pre>
  
  <p>Any help appreciated.</p>