Runs the search_google command line tool.
  
  This function runs the search_google command line tool 
  in a terminal. It was intended for use inside a py file 
  (.py) to be executed using python.
  
  Notes:
    * ``[q]`` reflects key ``q`` in the ``cseargs`` parameter for :class:`api.results`
    * Optional arguments with ``build_`` are keys in the ``buildargs`` parameter for :class:`api.results`
  
    For distribution, this function must be defined in the following files::
      
      # In 'search_google/search_google/__main__.py'
      from .cli import run
      run()
      
      # In 'search_google/search_google.py'
      from search_google.cli import run
      if __name__ == '__main__':
        run()
      
      # In 'search_google/__init__.py'
      __entry_points__ = {'console_scripts': ['search_google=search_google.cli:run']}
  
  Examples::
    
    # Import google_streetview for the cli module
    import search_google.cli
    
    # Create command line arguments
    argv = [
      'cli.py',
      'google',
      '--searchType=image',
      '--build_developerKey=your_dev_key',
      '--cx=your_cx_id'
      '--num=1'
    ]
    
    # Run command line
    search_google.cli.run(argv)

def run(argv=argv):
  """Runs the search_google command line tool.
  
  This function runs the search_google command line tool 
  in a terminal. It was intended for use inside a py file 
  (.py) to be executed using python.
  
  Notes:
    * ``[q]`` reflects key ``q`` in the ``cseargs`` parameter for :class:`api.results`
    * Optional arguments with ``build_`` are keys in the ``buildargs`` parameter for :class:`api.results`
  
    For distribution, this function must be defined in the following files::
      
      # In 'search_google/search_google/__main__.py'
      from .cli import run
      run()
      
      # In 'search_google/search_google.py'
      from search_google.cli import run
      if __name__ == '__main__':
        run()
      
      # In 'search_google/__init__.py'
      __entry_points__ = {'console_scripts': ['search_google=search_google.cli:run']}
  
  Examples::
    
    # Import google_streetview for the cli module
    import search_google.cli
    
    # Create command line arguments
    argv = [
      'cli.py',
      'google',
      '--searchType=image',
      '--build_developerKey=your_dev_key',
      '--cx=your_cx_id'
      '--num=1'
    ]
    
    # Run command line
    search_google.cli.run(argv)
    
  """
  config_file = kwconfig.manage(
    file_path=resource_filename(Requirement.parse('search_google'), 'search_google/config.json'),
    defaults={
      'build_serviceName': 'customsearch',
      'build_version': 'v1',
      'num': 3,
      'fileType': 'png',
      'option_silent': 'False',
      'option_preview' : 10})
  
  # (commands) Main command calls
  if len(argv) > 1:
    if argv[1] == '-i': # browse docs
      open_new_tab(_doc_link)
      exit()
    elif argv[1] == '-a': # browse arguments
      open_new_tab(_cse_link)
      exit()
  config_file.command(argv, i=1, doc=__doc__, quit=True, silent=False)
  
  # (parse_args) Parse command arguments into dict
  kwargs = kwconfig.parse(argv[2:])
  kwargs['q'] = argv[1]
  kwargs = config_file.add(kwargs)
  
  # (split_args) Split args into build, cse, and save arguments
  buildargs = {}
  cseargs = {}
  saveargs = {}
  optionargs = {}
  for k, v in kwargs.items():
    if 'build_' == k[0:6]:
      buildargs[k[6:]] = v
    elif 'save_' == k[0:5]:
      saveargs[k[5:]] = v
    elif 'option_' == k[0:7]:
      optionargs[k[7:]] = v
    else:
      cseargs[k] = v
  
  # (cse_results) Get google api results
  results = search_google.api.results(buildargs, cseargs)
  
  # (cse_print) Print a preview of results
  if 'silent' in optionargs:
    if optionargs['silent'].lower() != 'true':
      results.preview(n=int(optionargs['preview']))
  
  # (cse_save) Save links and metadata
  if 'links' in saveargs:
    results.save_links(saveargs['links'])
  if 'metadata' in saveargs:
    results.save_metadata(saveargs['metadata'])
  
  # (cse_download) Download links
  if 'downloads' in saveargs:
    results.download_links(saveargs['downloads'])