From 132066b319fa0fb35c0ad052d4c7acb9403496c6 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sun, 19 May 2024 12:20:39 +0200 Subject: [PATCH] init --- pkgs/clan-cli/docs.py | 51 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-cli/docs.py b/pkgs/clan-cli/docs.py index cf342b8a9..4113a612c 100644 --- a/pkgs/clan-cli/docs.py +++ b/pkgs/clan-cli/docs.py @@ -284,6 +284,50 @@ def collect_commands() -> list[Category]: return result +class ManPage: + def __init__(self, name: str, section: int): + self.name = name + self.section = section + + def add_description(self, description: str) -> None: + self.description = description + + # def add_option(self, option, description): + # self.options[option] = description + + def control(self, control: str, content: str) -> None: + self.manpage = self.manpage + f".{control} {content}" + self.manpage = self.manpage + "\n" + + def render(self) -> str: + self.manpage = "" + self.control("TH", "Clan 1") + self.control("SH", "NAME") + # manpage = f"NAME\n\t{self.name} - {self.description}\n\nDESCRIPTION\n\t{self.description}\n\nOPTIONS\n" + + # for option, desc in self.options.items(): + # manpage += f"\t-{option}\n\t\t{desc}\n" + + return self.manpage + + +def build_manpage() -> None: + """ + Build the reference and write to the out path. + """ + cmds = collect_commands() + # print(cmds) + # start the manpage with information collect_commands() doesn't expose + man = ManPage("clan", 1) + man.add_description("The clan cli tool.") + + print(man.render()) + + # folder = Path("out") + # folder.mkdir(parents=True, exist_ok=True) + pass + + def build_command_reference() -> None: """ Function that will build the reference @@ -295,13 +339,12 @@ def build_command_reference() -> None: folder.mkdir(parents=True, exist_ok=True) # Index file - markdown = "# CLI Overview\n\n" + markdown = "#Overview\n\n" categories_fmt = "" for cat in cmds: categories_fmt += f"{cat.to_md_li()}\n\n" if cat.to_md_li() else "" if categories_fmt: - markdown += """## Overview\n\n""" markdown += '
\n\n' markdown += categories_fmt markdown += "
" @@ -375,13 +418,15 @@ def build_command_reference() -> None: def main() -> None: if len(sys.argv) != 2: print("Usage: python docs.py ") - print("Available commands: reference") + print("Available commands: reference, manpage") sys.exit(1) command = sys.argv[1] if command == "reference": build_command_reference() + if command == "manpage": + build_manpage() if __name__ == "__main__":