Пример #1
0
    def _print_header(self, cli_name, help_file):
        super(CLIPrintMixin, self)._print_header(cli_name, help_file)

        links = help_file.links
        if links:
            link_text = "{} and {}".format(", ".join([link["url"] for link in links[0:-1]]),
                                           links[-1]["url"]) if len(links) > 1 else links[0]["url"]
            link_text = "For more information, see: {}\n".format(link_text)
            _print_indent(link_text, 2, width=self.textwrap_width)
Пример #2
0
    def show(self):
        from ._arg import AAZObjectArg, AAZDictArg, AAZListArg, AAZBaseArg
        assert self.schema is not None and isinstance(self.schema, AAZBaseArg)
        schema = self.schema
        schema_key = self.keys[0]
        idx = 1
        while idx < len(self.keys):
            key = self.keys[idx]
            if isinstance(schema, AAZObjectArg):
                try:
                    schema = schema[key]
                except AAZUndefinedValueError:
                    # show the help of current schema
                    break
                key = f'.{key}'
            elif isinstance(schema, AAZDictArg):
                try:
                    schema = schema.Element
                except AAZUnknownFieldError:
                    # show the help of current schema
                    break
                key = '{}'
            elif isinstance(schema, AAZListArg):
                try:
                    schema = schema.Element
                except AAZUnknownFieldError:
                    # show the help of current schema
                    break
                key = '[]'
            else:
                # show the help of current schema
                break
            schema_key += key
            idx += 1

        self._print_schema_basic(schema_key, schema)

        if isinstance(schema, AAZObjectArg):
            self._print_object_props_schema(schema, title="Object Properties")
        elif isinstance(schema, AAZDictArg) and isinstance(
                schema.Element, AAZObjectArg):
            self._print_object_props_schema(schema.Element,
                                            title="Dict Element Properties")
        elif isinstance(schema, AAZListArg) and isinstance(
                schema.Element, AAZObjectArg):
            self._print_object_props_schema(schema.Element,
                                            title="List Element Properties")

        _print_indent("")
Пример #3
0
 def _print_examples(help_file):
     from colorama import Style
     indent = 0
     _print_indent('Examples', indent)
     for e in help_file.examples:
         indent = 1
         _print_indent(u'{0}'.format(e.short_summary), indent)
         indent = 2
         if e.long_summary:
             _print_indent(u'{0}'.format(e.long_summary), indent)
         _print_indent(u'{0}'.format(e.command), indent)
         print('')
     indent = 0
     message = 'For more specific examples, use: az find "az {}"'.format(
         help_file.command)
     _print_indent(Style.BRIGHT + message + Style.RESET_ALL + '\n', indent)
Пример #4
0
    def _print_object_props_schema(cls, schema, title):
        LINE_FORMAT = '{name}{padding}{tags}{separator}{short_summary}'

        _print_indent(f"\n{title}")
        layouts = []
        max_header_len = 0

        for prop_schema in schema._fields.values():
            prop_tags = cls._build_schema_tags(prop_schema)
            prop_name = ' '.join(prop_schema._options)

            prop_short_summary = cls._build_short_summery(prop_schema,
                                                          is_prop=True)

            prop_group_name = prop_schema._arg_group or ""
            header_len = len(prop_name) + len(prop_tags) + (1 if prop_tags else
                                                            0)
            if header_len > max_header_len:
                max_header_len = header_len
            layouts.append({
                "name":
                prop_name,
                "tags":
                prop_tags,
                'separator':
                FIRST_LINE_PREFIX if prop_short_summary else '',
                'short_summary':
                prop_short_summary,
                'group_name':
                prop_group_name,
                'header_len':
                header_len
            })

        layouts.sort(key=lambda a: (a['group_name'], 0
                                    if a['tags'] else 1, a['tags'], a['name']))
        for layout in layouts:
            if layout['tags']:
                pad_len = max_header_len - layout['header_len'] + 1
            else:
                pad_len = max_header_len - layout['header_len']
            layout['padding'] = ' ' * pad_len
            _print_indent(LINE_FORMAT.format(**layout),
                          indent=1,
                          subsequent_spaces=max_header_len + 4 +
                          len(FIRST_LINE_PREFIX) - 1)
Пример #5
0
 def _print_examples(help_file):
     indent = 0
     _print_indent('Examples', indent)
     for e in help_file.examples:
         indent = 1
         _print_indent('{0}'.format(e.short_summary), indent)
         indent = 2
         if e.long_summary:
             _print_indent('{0}'.format(e.long_summary), indent)
         _print_indent('{0}'.format(e.command), indent)
         print('')
Пример #6
0
 def _print_examples(help_file):
     indent = 0
     _print_indent('Examples', indent)
     for e in help_file.examples:
         indent = 1
         _print_indent(u'{0}'.format(e.short_summary), indent)
         indent = 2
         if e.long_summary:
             _print_indent(u'{0}'.format(e.long_summary), indent)
         _print_indent(u'{0}'.format(e.command), indent)
         print('')
Пример #7
0
    def _print_schema_basic(cls, key, schema):
        indent = 0
        _print_indent('\nArgument', indent)

        help_tags = cls._build_schema_tags(schema,
                                           preview=False,
                                           experimental=False)
        schema_type = schema._type_in_help
        if help_tags:
            _print_indent(f"{key} {help_tags}{FIRST_LINE_PREFIX}{schema_type}",
                          indent=1)
        else:
            _print_indent(f"{key}{FIRST_LINE_PREFIX}{schema_type}", indent=1)

        short_summary = cls._build_short_summery(schema)
        if short_summary:
            _print_indent(short_summary, indent=2)

        long_summary = cls._build_long_summery(schema)
        if long_summary:
            _print_indent(long_summary, indent=2)
Пример #8
0
 def _print_az_find_message(command):
     indent = 0
     message = 'To search AI knowledge base for examples, use: az find "az {}"'.format(
         command)
     _print_indent(message + '\n', indent)