title: Using Argparse with Google Admin API
body: <p>I am using Google's Python API to pull down auditing information, but I can't get the parent group arguments for argparse (which appear to be required for API access) and my own arguments (e.g. passing in a date) to work together.</p>
  
  <p>Code:</p>
  
  <pre><code>import pprint
  import sys
  import re
  import httplib2
  import json
  import collections
  import argparse
  
  from oauth2client import client
  from apiclient import sample_tools
  from apiclient import discovery
  from oauth2client.client import AccessTokenRefreshError
  from oauth2client.client import OAuth2WebServerFlow
  from oauth2client.file import Storage
  from oauth2client.tools import run
  from oauth2client import tools
  
  def main(argv): 
    # Parser for command-line arguments.
    parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])
  
    parser.add_argument("-d","--selected_date", help="Date (YYYY-mm-dd) to run user usage report", required=True)
  
    args = parser.parse_args(argv[1:])
    print args
    selected_date = args.selected_date
    print selected_date
  
    # Authenticate and construct service.
    service, flags = sample_tools.init(
    argv, 'admin', 'reports_v1', __doc__, __file__,
    scope='https://www.googleapis.com/auth/admin.reports.usage.readonly')
  
    # If the Credentials don't exist or are invalid run through the native client
    # flow. The Storage object will ensure that if successful the good
    # Credentials will get written back to a file.
    storage = Storage('admin.dat')
    credentials = storage.get()
    if not credentials or credentials.invalid:
      credentials = run(FLOW, storage)
  </code></pre>
  
  <p>And running it from the command line...</p>
  
  <pre><code>&gt; python user_report.py
  usage: user_report.py [-h] [--auth_host_name AUTH_HOST_NAME]
                    [--noauth_local_webserver]
                    [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                    [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] -d
                    SELECTED_DATE
  user_report.py: error: argument -d/--selected_date is required
  </code></pre>
  
  <p>Looks good so far... now add an argument</p>
  
  <pre><code>&gt; python user_report.py -d "2014-09-14"
  Namespace(auth_host_name='localhost', auth_host_port=[8080, 8090], logging_level='ERROR', noauth_local_webserver=False, selected_date='2014-09-14')
  usage: user_report.py [-h] [--auth_host_name AUTH_HOST_NAME]
                    [--noauth_local_webserver]
                    [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                    [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
  user_report.py: error: unrecognized arguments: -d 2014-09-14
  </code></pre>
  
  <p>It appears that the date argument is not recognized. Any help would be much appreciated!</p>