]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
initrd: add --show-documentation option 2990/head
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 5 Sep 2024 14:52:01 +0000 (16:52 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 5 Sep 2024 16:30:57 +0000 (18:30 +0200)
mkosi/__init__.py
mkosi/config.py
mkosi/documentation.py
mkosi/initrd.py

index a347e9cf4fbd51987a4709e4de255dd7a81dfbc6..c12f6268a2e1f4c030731ec11bff7046d65066de 100644 (file)
@@ -55,6 +55,7 @@ from mkosi.config import (
     Compression,
     Config,
     ConfigFeature,
+    DocFormat,
     JsonEncoder,
     KeySourceType,
     ManifestFormat,
@@ -3921,7 +3922,9 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
         return print_completion(args, resources=resources)
 
     if args.verb == Verb.documentation:
-        return show_docs(args, resources=resources)
+        manual = args.cmdline[0] if args.cmdline else "mkosi"
+        formats: list[DocFormat] = [args.doc_format] if args.doc_format != DocFormat.auto else DocFormat.all()
+        return show_docs(manual, formats, resources=resources, pager=args.pager)
 
     if args.verb == Verb.genkey:
         return generate_key_cert_pair(args)
index 001300c1a4909585e592caa03fbb6c64ca41c6c3..e25eecab223d0f4b917b057b68df1aa81a4fcc42 100644 (file)
@@ -247,6 +247,12 @@ class DocFormat(StrEnum):
     pandoc   = enum.auto()
     system   = enum.auto()
 
+    @classmethod
+    def all(cls) -> list["DocFormat"]:
+        # this excludes auto and encodes the order in which these should be
+        # checked when searching for docs
+        return [cls.man, cls.pandoc, cls.markdown, cls.system]
+
 
 class Bootloader(StrEnum):
     none         = enum.auto()
index e081d036be54f073d591ed1beed5443facc734bf..f1b39d11e44c407047875080b35f1fdeb0986855 100644 (file)
@@ -4,20 +4,13 @@ import logging
 import subprocess
 from pathlib import Path
 
-from mkosi.config import Args, DocFormat
+from mkosi.config import DocFormat
 from mkosi.log import die
 from mkosi.pager import page
 from mkosi.run import find_binary, run
 
 
-def show_docs(args: Args, *, resources: Path) -> None:
-    if args.doc_format == DocFormat.auto:
-        formats = [DocFormat.man, DocFormat.pandoc, DocFormat.markdown, DocFormat.system]
-    else:
-        formats = [args.doc_format]
-
-    manual = args.cmdline[0] if args.cmdline else "mkosi"
-
+def show_docs(manual: str, formats: list[DocFormat], *, resources: Path, pager: bool = True) -> None:
     while formats:
         form = formats.pop(0)
         try:
@@ -39,7 +32,7 @@ def show_docs(args: Args, *, resources: Path) -> None:
                 run(["man", "--local-file", "-"], input=pandoc.stdout)
                 return
             elif form == DocFormat.markdown:
-                page((resources / f"man/{manual}.md").read_text(), args.pager)
+                page((resources / f"man/{manual}.md").read_text(), pager)
                 return
             elif form == DocFormat.system:
                 run(["man", manual], log=False)
index c3fe848872232e577d4aa072f10d73e41175c04c..6a8d569db397e2fdd84a1a6d17becab4ea58cbdf 100644 (file)
@@ -8,11 +8,14 @@ import sys
 import tempfile
 from pathlib import Path
 
-from mkosi.config import OutputFormat
+import mkosi.resources
+from mkosi.config import DocFormat, OutputFormat
+from mkosi.documentation import show_docs
 from mkosi.log import log_setup
 from mkosi.run import find_binary, run, uncaught_exception_handler
 from mkosi.sandbox import __version__
 from mkosi.types import PathString
+from mkosi.util import resource_path
 
 
 @uncaught_exception_handler()
@@ -62,6 +65,12 @@ def main() -> None:
         action="store_true",
         default=False,
     )
+    parser.add_argument(
+        "-D", "--show-documentation",
+        help="Show the man page",
+        action="store_true",
+        default=False,
+    )
     parser.add_argument(
         "--version",
         action="version",
@@ -70,6 +79,11 @@ def main() -> None:
 
     args = parser.parse_args()
 
+    if args.show_documentation:
+        with resource_path(mkosi.resources) as r:
+            show_docs("mkosi-initrd", DocFormat.all(), resources=r)
+        return
+
     cmdline: list[PathString] = [
         "mkosi",
         "--force",