feat: can remove header when generate a table

This commit is contained in:
egarette@silique.fr 2025-10-14 16:42:39 +02:00
parent e97f4b4ca6
commit bebea05e7c
3 changed files with 12 additions and 7 deletions

View file

@ -112,11 +112,11 @@ class Formater(CommonFormater):
"""Dump yaml part of documentation""" """Dump yaml part of documentation"""
return f"[,yaml]\n----\n---\n{dump(_dump)}\n----\n" return f"[,yaml]\n----\n---\n{dump(_dump)}\n----\n"
def table(self, datas) -> str: def table(self, datas: list, with_header: bool=True) -> str:
"""Transform list to a table in string format """Transform list to a table in string format
we change the first line because we want that col has the same width we change the first line because we want that col has the same width
""" """
table = super().table(datas) table = super().table(datas, with_header)
stable = table.split("\n", 1) stable = table.split("\n", 1)
return '[cols="1a,1a"]\n' + stable[1] return '[cols="1a,1a"]\n' + stable[1]

View file

@ -154,11 +154,12 @@ class Formater(CommonFormater):
for l in line.split(self.enter_table): for l in line.split(self.enter_table):
self.max_line = max(self.max_line, len(l) + 1) self.max_line = max(self.max_line, len(l) + 1)
def table(self, datas: list) -> str: def table(self, datas: list, with_header: bool=True) -> str:
"""Transform list to a table in string format""" """Transform list to a table in string format"""
table = self.rich_table(show_lines=True) table = self.rich_table(show_lines=True)
table.add_column(_("Variable"), width=self.max_line) if with_header:
table.add_column(_("Description"), width=self.max_line) table.add_column(_("Variable"), width=self.max_line)
table.add_column(_("Description"), width=self.max_line)
for data in datas: for data in datas:
table.add_row(str(data[0]), data[1]) table.add_row(str(data[0]), data[1])
return table return table

View file

@ -650,12 +650,16 @@ class CommonFormater:
"""Manage column""" """Manage column"""
return return
def table(self, datas: list) -> str: def table(self, datas: list, with_header: bool=True) -> str:
"""Transform list to a table in string format""" """Transform list to a table in string format"""
if with_header:
headers = self.table_header([_("Variable"), _("Description")])
else:
headers = ()
msg = ( msg = (
tabulate( tabulate(
datas, datas,
headers=self.table_header([_("Variable"), _("Description")]), headers=headers,
tablefmt=self._table_name, tablefmt=self._table_name,
) )
+ "\n\n" + "\n\n"