Example #1
0
        for each item in each slice. Multiple keys and slices may be specified.
        This also flattens keys for *--format* and *--filter*. For example,
        *--flatten=abc.def* flattens *abc.def[].ghi* references to
        *abc.def.ghi*. A resource record containing *abc.def[]* with N elements
        will expand to N records in the flattened output. This flag interacts
        with other flags that are applied in this order: *--flatten*,
        *--sort-by*, *--filter*, *--limit*.""")

FORMAT_FLAG = Argument('--format',
                       default=None,
                       category=COMMONLY_USED_FLAGS,
                       help="""\
        Set 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())))

LIST_COMMAND_FLAGS = 'LIST COMMAND'

ASYNC_FLAG = Argument('--async',
                      action='store_true',
                      dest='async_',
                      help="""\
    Return immediately, without waiting for the operation in progress to
    complete.""")

FILTER_FLAG = Argument('--filter',
                       metavar='EXPRESSION',
                       require_coverage_in_tests=False,
                       category=LIST_COMMAND_FLAGS,
                       help="""\
Example #2
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.')

        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.',
            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('--flatten',
                                    metavar='KEY',
                                    default=None,
                                    type=arg_parsers.ArgList(),
                                    category=calliope_base.COMMONLY_USED_FLAGS,
                                    help="""\
        Flatten _name_[] output resource slices in _KEY_ into separate records
        for each item in each slice. Multiple keys and slices may be specified.
        This also flattens keys for *--format* and *--filter*. For example,
        *--flatten=abc.def[]* flattens *abc.def[].ghi* references to
        *abc.def.ghi*. A resource record containing *abc.def[]* with N elements
        will expand to N records in the flattened output. This flag interacts
        with other flags that are applied in this order: *--flatten*,
        *--sort-by*, *--filter*, *--limit*.""")

        top_element.ai.add_argument(
            '--format',
            default=None,
            category=calliope_base.COMMONLY_USED_FLAGS,
            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',
            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)
Example #3
0
 def testGetSupportedFormatsAndFormatRegistry(self):
     expected = resource_printer.SupportedFormats()
     registry = resource_printer.GetFormatRegistry()
     actual = sorted(registry)
     self.assertEqual(expected, actual)
Example #4
0
 def testSupportedFormats(self):
     formats = resource_printer.SupportedFormats()
     self.assertIn('default', formats)
     self.assertIn('none', formats)
     self.assertIn('yaml', formats)
Example #5
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)
Example #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)