def SetUp(self):
     self.choices = None
     self.parser = parser_extensions.ArgumentParser(
         calliope_command='flags-test', )
     self.StartObjectPatch(self.parser,
                           'add_argument',
                           side_effect=self.MockAddArgument)
Exemple #2
0
  def _AssignParser(self, parser_group, allow_positional_args):
    """Assign a parser group to model this Command or CommandGroup.

    Args:
      parser_group: argparse._ArgumentGroup, the group that will model this
          command or group's arguments.
      allow_positional_args: bool, Whether to allow positional args for this
          group or not.

    """
    if not parser_group:
      # This is the root of the command tree, so we create the first parser.
      self._parser = parser_extensions.ArgumentParser(
          description=self.long_help,
          add_help=False,
          prog=self.dotted_name,
          calliope_command=self)
    else:
      # This is a normal sub group, so just add a new subparser to the existing
      # one.
      self._parser = parser_group.add_parser(
          self.cli_name,
          help=self.short_help,
          description=self.long_help,
          add_help=False,
          prog=self.dotted_name,
          calliope_command=self)

    self._sub_parser = None

    self.ai = parser_arguments.ArgumentInterceptor(
        parser=self._parser,
        is_global=not parser_group,
        cli_generator=self._cli_generator,
        allow_positional=allow_positional_args)

    self.ai.add_argument(
        '-h', action=actions.ShortHelpAction(self),
        is_replicated=True,
        category=base.COMMONLY_USED_FLAGS,
        help='Print a summary help and exit.')
    self.ai.add_argument(
        '--help', action=actions.RenderDocumentAction(self, '--help'),
        is_replicated=True,
        category=base.COMMONLY_USED_FLAGS,
        help='Display detailed help.')
    self.ai.add_argument(
        '--document', action=actions.RenderDocumentAction(self),
        is_replicated=True,
        nargs=1,
        metavar='ATTRIBUTES',
        type=arg_parsers.ArgDict(),
        hidden=True,
        help='THIS TEXT SHOULD BE HIDDEN')

    self._AcquireArgs()
Exemple #3
0
def ArgumentParser(cli_name='test'):
    """Gets a calliope argument parser with all intercepts in place."""
    command = MockCommand(cli_name)
    wrapped_parser = parser_extensions.ArgumentParser(calliope_command=command)
    parser = parser_arguments.ArgumentInterceptor(parser=wrapped_parser,
                                                  cli_generator=None,
                                                  allow_positional=True)
    command.ai = parser
    parser.parse_args = wrapped_parser.parse_args  # For test use only.
    return parser
    def SetUp(self):
        # Set up a sample argparse parser.
        command = calliope_util.MockCommand('command')
        argparser = parser_extensions.ArgumentParser(calliope_command=command)
        self.parser = parser_arguments.ArgumentInterceptor(
            parser=argparser, cli_generator=None, allow_positional=True)
        command.ai = self.parser

        # Set up a default fallthrough.
        def Fallthrough():
            return '!'

        self.fallthrough = deps.Fallthrough(Fallthrough, hint='h')
Exemple #5
0
 def __init__(self, args=None, command_name='test', command_resources=None,
              cli=None, command_only=False, handler_info=None, **kwargs):
   self._calliope_command = MockCommand(command_name)
   self._cli = cli
   self._command_only = command_only
   parser = parser_extensions.ArgumentParser(
       add_help=False,
       prog=command_name,
       calliope_command=self._calliope_command)
   self._calliope_command.ai = parser_arguments.ArgumentInterceptor(parser)
   self._calls = {}
   self._commands = []
   self._command_resources = command_resources or {}
   self._handler_info = handler_info or {}
   dests = {}
   if args:
     for name, value in six.iteritems(args):
       self._calliope_command.ai.add_argument(name, help='Auxilio aliis.')
       dests[name.replace('-', '_').strip('_')] = value
   super(MockNamespace, self).__init__(**dests)
 def SetUp(self):
     command = calliope_test_util.MockCommand('test')
     self.parser = parser_extensions.ArgumentParser(
         calliope_command=command)