コード例 #1
0
ファイル: cli.py プロジェクト: phrayezzen/media-database
    def __AddBuiltinGlobalFlags(self, top_element):
        """Adds in calliope builtin global flags.

    This needs to happen immediately after the top group is loaded and before
    any other groups are loaded.  The flags must be present so when sub groups
    are loaded, the flags propagate down.

    Args:
      top_element: backend._CommandCommon, The root of the command tree.
    """
        if self.__version_func is not None:
            # pylint: disable=protected-access
            top_element.ai.add_argument('-v',
                                        '--version',
                                        group_flag=True,
                                        action=actions.FunctionExitAction(
                                            self.__version_func),
                                        help='Print version information.')
        # pylint: disable=protected-access
        top_element.ai.add_argument(
            '--verbosity',
            choices=log.OrderedVerbosityNames(),
            default=None,
            help=
            ('Override the default verbosity for this command.  This must be '
             'a standard logging verbosity level: [{values}] (Default: '
             '[{default}]).').format(values=', '.join(
                 log.OrderedVerbosityNames()),
                                     default=log.DEFAULT_VERBOSITY_STRING),
            action=actions.StoreProperty(properties.VALUES.core.verbosity))
        top_element.ai.add_argument(
            '--user-output-enabled',
            default=None,
            choices=('true', 'false'),
            help=
            ('Control whether user intended output is printed to the console.  '
             '(true/false)'),
            action=actions.StoreProperty(
                properties.VALUES.core.user_output_enabled))
        format_flag = top_element.ai.add_argument(
            '--format',
            choices=resource_printer.SUPPORTED_FORMATS,
            help='Format for printed output.')
        format_flag.detailed_help = """\
        Specify a format for printed output. By default, a command-specific
        human-friendly output format is used. Setting this flag to one of
        the available options will serialize the result of the command in
        the chosen format and print it to stdout. Supported formats are:
        `{0}`.""".format('`, `'.join(resource_printer.SUPPORTED_FORMATS))

        # Logs all HTTP server requests and responses to stderr.
        top_element.ai.add_argument(
            '--log-http',
            action='store_true',
            default=None,
            help='Logs all HTTP server requests and responses to stderr.')

        # Timeout value for HTTP requests.
        top_element.ai.add_argument('--http-timeout',
                                    default=None,
                                    type=float,
                                    help=argparse.SUPPRESS)
コード例 #2
0
ファイル: cli.py プロジェクト: adambengis/TraderGrows
    def __AddBuiltinGlobalFlags(self, top_element):
        """Adds in calliope builtin global flags.

    This needs to happen immediately after the top group is loaded and before
    any other groups are loaded.  The flags must be present so when sub groups
    are loaded, the flags propagate down.

    Args:
      top_element: backend._CommandCommon, The root of the command tree.
    """
        calliope_base.FLAGS_FILE_FLAG.AddToParser(top_element.ai)
        calliope_base.FLATTEN_FLAG.AddToParser(top_element.ai)
        calliope_base.FORMAT_FLAG.AddToParser(top_element.ai)

        if self.__version_func is not None:
            top_element.ai.add_argument(
                '-v',
                '--version',
                do_not_propagate=True,
                category=calliope_base.COMMONLY_USED_FLAGS,
                action=actions.FunctionExitAction(self.__version_func),
                help=
                'Print version information and exit. This flag is only available'
                ' at the global level.')

        top_element.ai.add_argument('--configuration',
                                    metavar='CONFIGURATION',
                                    category=calliope_base.COMMONLY_USED_FLAGS,
                                    help="""\
        The configuration to use for this command invocation. For more
        information on how to use configurations, run:
        `gcloud topic configurations`.  You can also use the [{0}] environment
        variable to set the equivalent of this flag for a terminal
        session.""".format(config.CLOUDSDK_ACTIVE_CONFIG_NAME))

        top_element.ai.add_argument(
            '--verbosity',
            choices=log.OrderedVerbosityNames(),
            default=log.DEFAULT_VERBOSITY_STRING,
            category=calliope_base.COMMONLY_USED_FLAGS,
            help=
            ('Override the default verbosity for this command with any of the '
             'supported standard verbosity levels: {}.'.format(', '.join(
                 ['`' + name + '`' for name in log.OrderedVerbosityNames()]))),
            action=actions.StoreProperty(properties.VALUES.core.verbosity))

        # This should be a pure Boolean flag, but the alternate true/false explicit
        # value form is preserved for backwards compatibility. This flag and
        # is the only Cloud SDK outlier.
        # TODO(b/24095744): Add true/false deprecation message.
        top_element.ai.add_argument(
            '--user-output-enabled',
            metavar=
            ' ',  # Help text will look like the flag does not have a value.
            nargs='?',
            default=None,  # Tri-valued, None => don't override the property.
            const='true',
            choices=('true', 'false'),
            action=actions.StoreBooleanProperty(
                properties.VALUES.core.user_output_enabled),
            help='Print user intended output to the console.')

        top_element.ai.add_argument(
            '--log-http',
            default=None,  # Tri-valued, None => don't override the property.
            action=actions.StoreBooleanProperty(
                properties.VALUES.core.log_http),
            help='Log all HTTP server requests and responses to stderr.')

        top_element.ai.add_argument(
            '--authority-selector',
            default=None,
            action=actions.StoreProperty(
                properties.VALUES.auth.authority_selector),
            hidden=True,
            help='THIS ARGUMENT NEEDS HELP TEXT.')

        top_element.ai.add_argument(
            '--authorization-token-file',
            default=None,
            action=actions.StoreProperty(
                properties.VALUES.auth.authorization_token_file),
            hidden=True,
            help='THIS ARGUMENT NEEDS HELP TEXT.')

        top_element.ai.add_argument(
            '--credential-file-override',
            action=actions.StoreProperty(
                properties.VALUES.auth.credential_file_override),
            hidden=True,
            help='THIS ARGUMENT NEEDS HELP TEXT.')

        # Timeout value for HTTP requests.
        top_element.ai.add_argument('--http-timeout',
                                    default=None,
                                    action=actions.StoreProperty(
                                        properties.VALUES.core.http_timeout),
                                    hidden=True,
                                    help='THIS ARGUMENT NEEDS HELP TEXT.')

        # --flags-file source line number hook.
        FLAG_INTERNAL_FLAG_FILE_LINE.AddToParser(top_element.ai)
コード例 #3
0
  def __AddBuiltinGlobalFlags(self, top_element):
    """Adds in calliope builtin global flags.

    This needs to happen immediately after the top group is loaded and before
    any other groups are loaded.  The flags must be present so when sub groups
    are loaded, the flags propagate down.

    Args:
      top_element: backend._CommandCommon, The root of the command tree.
    """
    if self.__version_func is not None:
      top_element.ai.add_argument(
          '-v', '--version',
          do_not_propagate=True,
          category=calliope_base.COMMONLY_USED_FLAGS,
          action=actions.FunctionExitAction(self.__version_func),
          help='Print version information and exit. This flag is only available'
          ' at the global level.')

    configuration_flag = top_element.ai.add_argument(
        '--configuration',
        metavar='CONFIGURATION',
        category=calliope_base.COMMONLY_USED_FLAGS,
        help='The configuration to use for this command invocation.')
    configuration_flag.detailed_help = (
        'The configuration to use for this command invocation. For more '
        'information on how to use configurations, run:  '
        '`gcloud topic configurations`.  You can also use the [{0}] environment'
        ' variable to set the equivalent of this flag for a terminal session.'
        .format(config.CLOUDSDK_ACTIVE_CONFIG_NAME))

    top_element.ai.add_argument(
        '--verbosity',
        choices=log.OrderedVerbosityNames(),
        default=None,
        category=calliope_base.COMMONLY_USED_FLAGS,
        help=(
            'Override the default verbosity for this command.  This must be '
            'a standard logging verbosity level: [{values}] (Default: '
            '[{default}]).').format(
                values=', '.join(log.OrderedVerbosityNames()),
                default=log.DEFAULT_VERBOSITY_STRING),
        action=actions.StoreProperty(properties.VALUES.core.verbosity))

    # This should be a pure Boolean flag, but the alternate true/false explicit
    # value form is preserved for backwards compatibility. This flag and
    # is the only Cloud SDK outlier.
    # TODO(user): b/24095744: Add true/false deprecation message.
    top_element.ai.add_argument(
        '--user-output-enabled',
        metavar=' ',  # Help text will look like the flag does not have a value.
        nargs='?',
        default=None,  # Tri-valued, None => don't override the property.
        const='true',
        choices=('true', 'false'),
        action=actions.StoreBooleanProperty(
            properties.VALUES.core.user_output_enabled),
        help='Print user intended output to the console.')

    format_flag = top_element.ai.add_argument(
        '--format',
        default=None,
        category=calliope_base.COMMONLY_USED_FLAGS,
        help='The format for printing command output resources.')
    format_flag.detailed_help = """\
        Sets the format for printing command output resources. The default is a
        command-specific human-friendly output format. The supported formats
        are: `{0}`. For more details run $ gcloud topic formats.""".format(
            '`, `'.join(resource_printer.SupportedFormats()))

    top_element.ai.add_argument(
        '--log-http',
        nargs=0,
        default=None,  # Tri-valued, None => don't override the property.
        action=actions.StoreBooleanProperty(properties.VALUES.core.log_http),
        help='Log all HTTP server requests and responses to stderr.')

    top_element.ai.add_argument(
        '--authority-selector',
        default=None,
        action=actions.StoreProperty(properties.VALUES.auth.authority_selector),
        help=argparse.SUPPRESS)

    top_element.ai.add_argument(
        '--authorization-token-file',
        default=None,
        action=actions.StoreProperty(
            properties.VALUES.auth.authorization_token_file),
        help=argparse.SUPPRESS)

    top_element.ai.add_argument(
        '--credential-file-override',
        action=actions.StoreProperty(
            properties.VALUES.auth.credential_file_override),
        help=argparse.SUPPRESS)

    # Timeout value for HTTP requests.
    top_element.ai.add_argument(
        '--http-timeout',
        default=None,
        action=actions.StoreProperty(properties.VALUES.core.http_timeout),
        help=argparse.SUPPRESS)
コード例 #4
0
    def _AssignParser(self, parser_group, help_func, 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.
      help_func: func([str]), The long help function that is used for --help.
      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 = ArgumentParser(description=self.long_help,
                                          add_help=False,
                                          prog='.'.join(self._path),
                                          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='.'.join(self._path),
                                                   calliope_command=self)

        self._sub_parser = None

        self._ai = ArgumentInterceptor(parser=self._parser,
                                       allow_positional=allow_positional_args)

        self._short_help_action = actions.ShortHelpAction(self, self._ai)

        self._ai.add_argument('-h',
                              action=self._short_help_action,
                              help='Print a summary help and exit.')

        if help_func:

            def LongHelp():
                help_func(self._path,
                          default=usage_text.ShortHelpText(self, self._ai))

            long_help_action = actions.FunctionExitAction(LongHelp)
        else:
            long_help_action = self._short_help_action

        self._ai.add_argument('--help',
                              action=long_help_action,
                              help='Display detailed help.')

        def Markdown(command):
            """Returns an action that lists the markdown help for command."""
            class Action(argparse.Action):
                def __call__(self,
                             parser,
                             namespace,
                             values,
                             option_string=None):
                    command.LoadAllSubElements()
                    markdown.Markdown(command, sys.stdout.write)
                    sys.exit(0)

            return Action

        self._ai.add_argument('--markdown',
                              action=Markdown(self),
                              nargs=0,
                              help=argparse.SUPPRESS)

        self._AcquireArgs()
コード例 #5
0
  def _AssignParser(self, parser_group, help_func, 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.
      help_func: func([str]), The long help function that is used for --help.
      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 = argparse.ArgumentParser(description=self.long_help,
                                             add_help=False,
                                             prog='.'.join(self._path))
    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='.'.join(self._path))

    # Here we monkeypatch into argparse.
    # pylint:disable=protected-access
    self._parser._check_value = usage_text.CheckValueAndSuggest
    self._parser.error = usage_text.PrintParserError(self._parser)
    self._parser._parse_optional = actions.ParseOptionalForRemainder(
        self._parser)

    self._sub_parser = None

    self._ai = ArgumentInterceptor(
        parser=self._parser,
        allow_positional=allow_positional_args)

    self._short_help_action = actions.ShortHelpAction(self, self._ai)

    self._ai.add_argument(
        '-h', action=self._short_help_action,
        help='Print a summary help and exit.')

    if help_func:
      def LongHelp():
        help_func(
            self._path,
            default=usage_text.ShortHelpText(self, self._ai))
      long_help_action = actions.FunctionExitAction(LongHelp)
    else:
      long_help_action = self._short_help_action

    self._ai.add_argument(
        '--help', action=long_help_action,
        help='Display detailed help.')

    def Markdown(command):
      """Returns an action that lists the markdown help for command."""

      class Action(argparse.Action):

        def __call__(self, parser, namespace, values, option_string=None):
          markdown.Markdown(command, sys.stdout.write)
          sys.exit(0)

      return Action

    self._ai.add_argument(
        '--markdown', action=Markdown(self),
        nargs=0,
        help=argparse.SUPPRESS)

    if not parser_group:
      format_flag = self._ai.add_argument(
          '--format', help='Format for printed output.',
          choices=resource_printer.SUPPORTED_FORMATS)
      format_flag.detailed_help = """\
          Specify a format for printed output. By default, a command-specific
          human-friendly output format is used. Setting this flag to one of
          the available options will serialize the result of the command in
          the chosen format and print it to stdout. Supported formats are:
          `{0}`.""".format('`, `'.join(resource_printer.SUPPORTED_FORMATS))

    self._parser.parse_args = usage_text.ErrFuncParseArgs(self._parser)
    self._AcquireArgs()
コード例 #6
0
    def __AddBuiltinGlobalFlags(self, top_element):
        """Adds in calliope builtin global flags.

    This needs to happen immediately after the top group is loaded and before
    any other groups are loaded.  The flags must be present so when sub groups
    are loaded, the flags propagate down.

    Args:
      top_element: backend._CommandCommon, The root of the command tree.
    """
        if self.__version_func is not None:
            top_element.ai.add_argument('-v',
                                        '--version',
                                        group_flag=True,
                                        action=actions.FunctionExitAction(
                                            self.__version_func),
                                        help='Print version information.')

        top_element.ai.add_argument(
            '--verbosity',
            choices=log.OrderedVerbosityNames(),
            default=None,
            help=
            ('Override the default verbosity for this command.  This must be '
             'a standard logging verbosity level: [{values}] (Default: '
             '[{default}]).').format(values=', '.join(
                 log.OrderedVerbosityNames()),
                                     default=log.DEFAULT_VERBOSITY_STRING),
            action=actions.StoreProperty(properties.VALUES.core.verbosity))

        # This should be a pure Boolean flag, but the alternate true/false explicit
        # value form is preserved for backwards compatibility. This flag and
        # is the only Cloud SDK outlier.
        # TODO(gsfowler): b/24095744: Add true/false deprecation message.
        top_element.ai.add_argument(
            '--user-output-enabled',
            metavar=
            ' ',  # Help text will look like the flag does not have a value.
            nargs='?',
            default=None,  # Tri-valued, None => don't override the property.
            const='true',
            choices=('true', 'false'),
            action=actions.StoreBooleanProperty(
                properties.VALUES.core.user_output_enabled),
            help='Print user intended output to the console.')

        format_flag = top_element.ai.add_argument(
            '--format',
            default=None,
            help='The format for printing command output resources.')
        format_flag.detailed_help = """\
        Sets the format for printing command output resources. The default is a
        command-specific human-friendly output format. The supported formats
        are: `{0}`. For more details run $ gcloud topic formats.""".format(
            '`, `'.join(resource_printer.SupportedFormats()))

        top_element.ai.add_argument(
            '--log-http',
            nargs=0,
            default=None,  # Tri-valued, None => don't override the property.
            action=actions.StoreBooleanProperty(
                properties.VALUES.core.log_http),
            help='Log all HTTP server requests and responses to stderr.')

        # Timeout value for HTTP requests.
        top_element.ai.add_argument('--http-timeout',
                                    default=None,
                                    type=float,
                                    help=argparse.SUPPRESS)