示例#1
0
    def _should_include_example(self, ex):
        supported_profiles = ex.get('supported-profiles')
        unsupported_profiles = ex.get('unsupported-profiles')

        if all((supported_profiles, unsupported_profiles)):
            raise HelpAuthoringException(
                "An example cannot have both supported-profiles and unsupported-profiles."
            )

        if 'min_profile' in ex or 'max_profile' in ex:
            raise HelpAuthoringException(
                "Help entry fields 'min_profile' and 'max_profile' are no longer supported. "
                "Please use 'supported-profiles' or 'unsupported-profiles'.")

        if supported_profiles:
            supported_profiles = [
                profile.strip() for profile in supported_profiles.split(',')
            ]
            return self.help_ctx.cli_ctx.cloud.profile in supported_profiles

        if unsupported_profiles:
            unsupported_profiles = [
                profile.strip() for profile in unsupported_profiles.split(',')
            ]
            return self.help_ctx.cli_ctx.cloud.profile not in unsupported_profiles

        return True
示例#2
0
    def test_help_loads(self):
        from azure.cli.core.commands.arm import add_id_parameters
        import knack.events as events

        cli = TestCli()
        parser_dict = {}
        cli = TestCli()
        try:
            cli.invoke(['-h'])
        except SystemExit:
            pass
        cmd_tbl = cli.invocation.commands_loader.command_table
        cli.invocation.parser.load_command_table(cmd_tbl)
        for cmd in cmd_tbl:
            try:
                cmd_tbl[cmd].loader.command_name = cmd
                cmd_tbl[cmd].loader.load_arguments(cmd)
            except KeyError:
                pass
        cli.register_event(events.EVENT_INVOKER_CMD_TBL_LOADED,
                           add_id_parameters)
        cli.raise_event(events.EVENT_INVOKER_CMD_TBL_LOADED,
                        command_table=cmd_tbl)
        cli.invocation.parser.load_command_table(cmd_tbl)
        _store_parsers(cli.invocation.parser, parser_dict)

        for name, parser in parser_dict.items():
            try:
                help_file = GroupHelpFile(
                    name, parser) if _is_group(parser) else CliCommandHelpFile(
                        name, parser)
                help_file.load(parser)
            except Exception as ex:
                raise HelpAuthoringException('{}, {}'.format(name, ex))
示例#3
0
    def test_help_loads(self):
        from azure.cli.core.commands.arm import register_global_subscription_argument, register_ids_argument
        import knack.events as events

        parser_dict = {}
        cli = DummyCli()
        help_ctx = cli.help_cls(cli)
        try:
            cli.invoke(['-h'])
        except SystemExit:
            pass
        cmd_tbl = cli.invocation.commands_loader.command_table
        cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
        for cmd in cmd_tbl:
            try:
                cmd_tbl[cmd].loader.command_name = cmd
                cmd_tbl[cmd].loader.load_arguments(cmd)
            except KeyError:
                pass
        cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_global_subscription_argument)
        cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_ids_argument)
        cli.raise_event(events.EVENT_INVOKER_CMD_TBL_LOADED, command_table=cmd_tbl)
        cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
        _store_parsers(cli.invocation.parser, parser_dict)

        # TODO: do we want to update this as it doesn't actually load all help.
        # We do have a CLI linter which does indeed load all help.
        for name, parser in parser_dict.items():
            try:
                help_file = GroupHelpFile(help_ctx, name, parser) if _is_group(parser) \
                    else CliCommandHelpFile(help_ctx, name, parser)
                help_file.load(parser)
            except Exception as ex:
                raise HelpAuthoringException('{}, {}'.format(name, ex))
示例#4
0
    def _should_include_example(self, ex):
        supported_profiles = ex.get('supported-profiles')
        unsupported_profiles = ex.get('unsupported-profiles')

        if all((supported_profiles, unsupported_profiles)):
            raise HelpAuthoringException(
                "An example cannot have both supported-profiles and unsupported-profiles."
            )

        if supported_profiles:
            supported_profiles = [
                profile.strip() for profile in supported_profiles.split(',')
            ]
            return self.help_ctx.cli_ctx.cloud.profile in supported_profiles

        if unsupported_profiles:
            unsupported_profiles = [
                profile.strip() for profile in unsupported_profiles.split(',')
            ]
            return self.help_ctx.cli_ctx.cloud.profile not in unsupported_profiles

        return True