1
0
forked from clan/clan-core

Compare commits

...

2 Commits

Author SHA1 Message Date
165c04f4bf WIP manpage 2024-05-30 12:59:46 +02:00
132066b319 init 2024-05-29 10:47:39 +02:00
3 changed files with 350 additions and 3 deletions

0
pkgs/clan-cli/clan.1 Normal file
View File

View File

@ -284,6 +284,139 @@ def collect_commands() -> list[Category]:
return result
class ManPage:
def __init__(self, name: str, section: int) -> None:
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 = None) -> None:
if content:
self.manpage = self.manpage + f".{control} {content}"
else:
self.manpage = self.manpage + f".{control}"
self.manpage = self.manpage + "\n"
def line(self, content: str | None = None) -> None:
self.manpage = self.manpage + f"{content}"
self.manpage = self.manpage + "\n"
def newline(self) -> None:
self.manpage = self.manpage + "\n"
def paragraph(self) -> None:
self.newline()
self.control("PP")
def contribute(self) -> None:
"""
Contributing section of the manpages
should only be shown on the root page.
"""
self.control("SH", "CONTRIBUTE")
self.control(
"PP",
)
self.line("Bug reports, contributions and forks are welcome.")
self.newline()
self.control(
"PP",
)
self.line(
"The code lives on gitea, you can use the issue tracker to file bugs, or issues and give feedback."
)
self.newline()
self.line(self.link("https://git.clan.lol/clan/clan-core"))
self.paragraph()
self.line(
"There is a matrix channel available where you can give feedback, or get feedback."
)
self.line("Share your usage patterns or share tips and tricks.")
self.newline()
self.line(self.link("https://matrix.to/#/#clan:lassul.us"))
def link(self, link: str) -> str:
"""
Format a link
"""
return "\[la]" + link + "\[ra]"
def render(self) -> str:
self.manpage = ""
self.control("nh")
self.control("TH", 'CLAN 1 2023 clan "User Manuals"')
self.control("SH", "NAME")
self.control(
"PP",
)
# overview
self.line("clan - the clan cli tool")
self.newline()
# synopsis
self.control("SH", "SYNOPSIS")
self.control(
"PP",
)
self.line("clan [OPTIONS] [SUBCOMMAND]")
self.newline()
# description
self.control("SH", "DESCRIPTION")
self.control(
"PP",
)
self.line("clan is a distributed systems manager for your fingertips.")
self.line("It knows how to update your machines.")
self.line(
"It knows how to generate and manage secrets and facts for your services."
)
self.line(
"It knows which services have state in which directories and can manage backups for machines and services."
)
self.paragraph()
# manpage = f"NAME\n\t{self.name} - {self.description}\n\nDESCRIPTION\n\t{self.description}\n\nOPTIONS\n"
# for options in self.options.items():
# print(options)
# for option, desc in self.options.items():
# manpage += f"\t-{option}\n\t\t{desc}\n"
self.contribute()
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())
for command in cmds:
if command.title == "facts":
print(command)
# TODO: gather all level one subcommands
# folder = Path("out")
# folder.mkdir(parents=True, exist_ok=True)
pass
def build_command_reference() -> None:
"""
Function that will build the reference
@ -295,13 +428,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 += '<div class="grid cards" markdown>\n\n'
markdown += categories_fmt
markdown += "</div>"
@ -375,13 +507,15 @@ def build_command_reference() -> None:
def main() -> None:
if len(sys.argv) != 2:
print("Usage: python docs.py <command>")
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__":

View File

@ -0,0 +1,213 @@
{
"nodes": {
"clan-core": {
"inputs": {
"disko": "disko",
"flake-parts": "flake-parts",
"nixos-generators": "nixos-generators",
"nixos-images": "nixos-images",
"nixpkgs": "nixpkgs",
"sops-nix": "sops-nix",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1716971153,
"narHash": "sha256-3QXK2SJRLMBOB1urY64WpXPKIWcq1LilBO8xeD6cBZg=",
"ref": "refs/heads/main",
"rev": "d138e29a53678c94c600a4aeb125c2ece0267271",
"revCount": 2911,
"type": "git",
"url": "https://git.clan.lol/clan/clan-core"
},
"original": {
"type": "git",
"url": "https://git.clan.lol/clan/clan-core"
}
},
"disko": {
"inputs": {
"nixpkgs": [
"clan-core",
"nixpkgs"
]
},
"locked": {
"lastModified": 1716394172,
"narHash": "sha256-B+pNhV8GFeCj9/MoH+qtGqKbgv6fU4hGaw2+NoYYtB0=",
"owner": "nix-community",
"repo": "disko",
"rev": "23c63fb09334c3e8958b57e2ddc3870b75b9111d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "disko",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"clan-core",
"nixpkgs"
]
},
"locked": {
"lastModified": 1715865404,
"narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixlib": {
"locked": {
"lastModified": 1712450863,
"narHash": "sha256-K6IkdtMtq9xktmYPj0uaYc8NsIqHuaAoRBaMgu9Fvrw=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "3c62b6a12571c9a7f65ab037173ee153d539905f",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixos-2311": {
"locked": {
"lastModified": 1715818734,
"narHash": "sha256-WvAJWCwPj/6quKcsgsvQYyZRxV8ho/yUzj0HZQ34DVU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "95742536dc6debb5a8b8b78b27001c38f369f1e7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "release-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixos-generators": {
"inputs": {
"nixlib": "nixlib",
"nixpkgs": [
"clan-core",
"nixpkgs"
]
},
"locked": {
"lastModified": 1716123454,
"narHash": "sha256-U2o4UPM/UsEyIX2p11+YEQgR9HY3PmjZ2mRl/x5e4xo=",
"owner": "nix-community",
"repo": "nixos-generators",
"rev": "a63e0c83dd83fe28cc571b97129e13373436bd82",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-generators",
"type": "github"
}
},
"nixos-images": {
"inputs": {
"nixos-2311": "nixos-2311",
"nixos-unstable": [
"clan-core",
"nixpkgs"
]
},
"locked": {
"lastModified": 1716132123,
"narHash": "sha256-rATSWbPaKQfZGaemu0tHL2xfCzVIVwpuTjk+KSBC+k4=",
"owner": "nix-community",
"repo": "nixos-images",
"rev": "8c9cab8c44434c12dafc465fbf61a710c5bceb08",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-images",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716127062,
"narHash": "sha256-2rk8FqB/iQV2d0vQLs684/Tj5PUHaS1sFwG7fng5vXE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8a2555763c48e2410054de3f52f7310ce3241ec5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable-small",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"clan-core": "clan-core"
}
},
"sops-nix": {
"inputs": {
"nixpkgs": [
"clan-core",
"nixpkgs"
],
"nixpkgs-stable": [
"clan-core"
]
},
"locked": {
"lastModified": 1716087663,
"narHash": "sha256-zuSAGlx8Qk0OILGCC2GUyZ58/SJ5R3GZdeUNQ6IS0fQ=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "0bf1808e70ce80046b0cff821c019df2b19aabf5",
"type": "github"
},
"original": {
"owner": "Mic92",
"repo": "sops-nix",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"clan-core",
"nixpkgs"
]
},
"locked": {
"lastModified": 1715940852,
"narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "2fba33a182602b9d49f0b2440513e5ee091d838b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}