예제 #1
0
def make_parser():
    """Make parser for command line args.

  Returns:
    A Parser object.
  """
    def add_kythe_field(parser, field):
        parser.add_argument("--" + field,
                            dest=field,
                            type=str,
                            action="store",
                            default="",
                            help="Part of kythe's file-level vname proto.")

    parser = argparse.ArgumentParser(usage="%(prog)s [options] input")
    add_kythe_field(parser, "kythe_corpus")
    add_kythe_field(parser, "kythe_root")
    parser.add_argument("inputs",
                        metavar="input",
                        nargs=1,
                        help="A .py file to index")
    parser.add_argument("--debug",
                        action="store_true",
                        dest="debug",
                        default=None,
                        help="Display debug output.")
    # Add options from pytype-single.
    wrapper = arg_parser.ParserWrapper(parser)
    pytype_config.add_basic_options(wrapper)
    return arg_parser.Parser(parser, wrapper.actions)
예제 #2
0
 def test_group(self):
     parser = argparse.ArgumentParser()
     wrapper = arg_parser.ParserWrapper(parser)
     wrapper.add_argument('--foo', dest='foo')
     group = wrapper.add_argument_group('test1')
     group.add_argument('--bar', dest='bar')
     subgroup = wrapper.add_argument_group('test2')
     subgroup.add_argument('--baz', dest='baz')
     self.assertSetEqual(set(wrapper.actions), {'foo', 'bar', 'baz'})
예제 #3
0
def make_parser():
  """Make parser for command line args.

  Returns:
    A Parser object.
  """

  parser = argparse.ArgumentParser(usage='%(prog)s [options] input [input ...]')
  parser.register('action', 'flatten', _FlattenAction)
  modes = parser.add_mutually_exclusive_group()
  modes.add_argument(
      '--tree', dest='tree', action='store_true', default=False,
      help='Display import tree.')
  modes.add_argument(
      '--unresolved', dest='unresolved', action='store_true', default=False,
      help='Display unresolved dependencies.')
  modes.add_argument(
      '--generate-config', dest='generate_config', type=str, action='store',
      default='',
      help='Write out a dummy configuration file.')
  parser.add_argument(
      '-v', '--verbosity', dest='verbosity', type=int, action='store',
      default=1,
      help='Set logging level: 0=ERROR, 1=WARNING (default), 2=INFO.')
  parser.add_argument(
      '--config', dest='config', type=str, action='store', default='',
      help='Configuration file.')
  parser.add_argument(
      '--version', action='store_true', dest='version', default=None,
      help=('Display pytype version and exit.'))

  # Adds options from the config file.
  types = config.make_converters()
  # For nargs=*, argparse calls type() on each arg individually, so
  # _FlattenAction flattens the list of sets of paths as we go along.
  for option in [
      (('-x', '--exclude'), {'nargs': '*', 'action': 'flatten'}),
      (('inputs',), {'metavar': 'input', 'nargs': '*', 'action': 'flatten'}),
      (('-k', '--keep-going'), {'action': 'store_true', 'type': None}),
      (('-j', '--jobs'), {'action': 'store', 'type': int, 'metavar': 'N'}),
      (('-P', '--pythonpath'),),
      (('-V', '--python-version'),)
  ]:
    _add_file_argument(parser, types, *option)
  output = parser.add_mutually_exclusive_group()
  _add_file_argument(output, types, ('-o', '--output'))
  output.add_argument(
      '-n', '--no-cache', dest='no_cache', action='store_true', default=False,
      help='Send pytype output to a temporary directory.')

  # Adds options from pytype-single.
  wrapper = arg_parser.ParserWrapper(parser)
  pytype_config.add_basic_options(wrapper)
  return Parser(parser, wrapper.actions)
예제 #4
0
def make_parser():
    """Construct a parser to run tests against."""

    parser = argparse.ArgumentParser()
    parser.add_argument('-v',
                        '--verbosity',
                        dest='verbosity',
                        type=int,
                        action='store',
                        default=1)
    parser.add_argument('--config',
                        dest='config',
                        type=str,
                        action='store',
                        default='')

    # Add options from pytype-single.
    wrapper = arg_parser.ParserWrapper(parser)
    pytype_config.add_basic_options(wrapper)
    return arg_parser.Parser(parser, wrapper.actions)