import optparse


def LoadOptionsFromFlags(argv):
  """Parse command-line arguments.

  Args:
    argv: The program argument vector (excluding the script name)

  Returns:
    A dictionary with key-value pairs for each of the options
  """
  usage_string = 'python dsplcheck.py [options] [DSPL XML file or zip archive]'

  parser = optparse.OptionParser(usage=usage_string)

  parser.set_defaults(verbose=True)
  parser.add_option('-q', '--quiet',
                    action='store_false', dest='verbose',
                    help='Quiet mode')

  parser.add_option(
      '-l', '--checking_level', dest='checking_level', type='choice',
      choices=['schema_only', 'schema_and_model', 'full'], default='full',
      help='Level of checking to do (default: full)')

  (options, args) = parser.parse_args(args=argv)

  if not len(args) == 1:
    parser.error('An XML file or DSPL zip archive is required')

  return {'verbose': options.verbose,
          'checking_level': options.checking_level,
          'file_path': args[0]}