def format_for_cli(self, console: Console) -> str: field_alias = console.magenta(f"{self.alias}") indent = " " required_or_default = "required" if self.required else f"default: {self.default}" type_info = console.cyan(f"{indent}type: {self.type_hint}, {required_or_default}") lines = [field_alias, type_info] if self.description: lines.extend(f"{indent}{line}" for line in textwrap.wrap(self.description, 80)) return "\n".join(f"{indent}{line}" for line in lines)
def format_for_cli(self, console: Console, *, longest_target_alias: int) -> str: chars_before_description = longest_target_alias + 2 alias = console.cyan(f"{self.alias}".ljust(chars_before_description)) if not self.description: description = "<no description>" else: description_lines = textwrap.wrap(self.description, 80 - chars_before_description) if len(description_lines) > 1: description_lines = [ description_lines[0], *(f"{' ' * chars_before_description}{line}" for line in description_lines[1:]), ] description = "\n".join(description_lines) return f"{alias}{description}\n"
def format_for_cli(self, console: Console, *, longest_backend: int, is_v2: bool) -> str: chars_before_description = longest_backend + 3 is_activated = self.is_v2_activated if is_v2 else self.is_v1_activated activated_icon = "*" if is_activated else " " name = console.cyan( f"{self.name}{activated_icon}".ljust(chars_before_description)) if not self.description: description = "<no description>" else: description_lines = textwrap.wrap(self.description, 80 - chars_before_description, break_long_words=False) if len(description_lines) > 1: description_lines = [ description_lines[0], *(f"{' ' * chars_before_description} {line}" for line in description_lines[1:]), ] description = "\n".join(description_lines) return f"{name} {description}\n"