]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
doc: make documentation command take an argument
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Fri, 30 Aug 2024 09:13:39 +0000 (11:13 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 5 Sep 2024 14:19:38 +0000 (16:19 +0200)
Also let's leave out errors if things don't work, but we're still trying. This
way the last message "No manual entry for foo" will bubble up.

mkosi/__init__.py
mkosi/config.py

index 8a94335c5cf24e69c76237353bbc3be7d7403c05..9064ccf4fa18b66971f738f60d1a5ac075af340a 100644 (file)
@@ -3592,11 +3592,13 @@ def show_docs(args: Args, *, resources: Path) -> None:
     else:
         formats = [args.doc_format]
 
+    manual = args.cmdline[0] if args.cmdline else "mkosi"
+
     while formats:
         form = formats.pop(0)
         try:
             if form == DocFormat.man:
-                man = resources / "man/mkosi.1"
+                man = resources / f"man/{manual}.1"
                 if not man.exists():
                     raise FileNotFoundError()
                 run(["man", "--local-file", man])
@@ -3604,19 +3606,24 @@ def show_docs(args: Args, *, resources: Path) -> None:
             elif form == DocFormat.pandoc:
                 if not find_binary("pandoc"):
                     logging.error("pandoc is not available")
-                pandoc = run(["pandoc", "-t", "man", "-s", resources / "man/mkosi.md"], stdout=subprocess.PIPE)
+                pandoc = run(
+                    ["pandoc", "-t", "man", "-s", resources / f"man/{manual}.md"],
+                    stdout=subprocess.PIPE,
+                    stderr=subprocess.DEVNULL,
+                    log=False,
+                )
                 run(["man", "--local-file", "-"], input=pandoc.stdout)
                 return
             elif form == DocFormat.markdown:
-                page((resources / "man/mkosi.md").read_text(), args.pager)
+                page((resources / f"man/{manual}.md").read_text(), args.pager)
                 return
             elif form == DocFormat.system:
-                run(["man", "mkosi"])
+                run(["man", manual], log=False)
                 return
         except (FileNotFoundError, subprocess.CalledProcessError) as e:
             if not formats:
                 if isinstance(e, FileNotFoundError):
-                    die("The mkosi package does not contain the man page.")
+                    die("The mkosi package does not contain the man page {manual:r}.")
                 raise e
 
 
index 71adc9e6113bf4ca96f76ded8434f352cb43ab5e..001300c1a4909585e592caa03fbb6c64ca41c6c3 100644 (file)
@@ -88,6 +88,7 @@ class Verb(StrEnum):
             Verb.coredumpctl,
             Verb.burn,
             Verb.completion,
+            Verb.documentation,
         )
 
     def needs_build(self) -> bool:
@@ -3220,18 +3221,18 @@ def create_argument_parser(chdir: bool = True) -> argparse.ArgumentParser:
         usage="\n  " + textwrap.dedent("""\
               mkosi [options…] {b}summary{e}
                 mkosi [options…] {b}cat-config{e}
-                mkosi [options…] {b}build{e}       [command line…]
-                mkosi [options…] {b}shell{e}       [command line…]
-                mkosi [options…] {b}boot{e}        [nspawn settings…]
-                mkosi [options…] {b}qemu{e}        [qemu parameters…]
-                mkosi [options…] {b}ssh{e}         [command line…]
-                mkosi [options…] {b}journalctl{e}  [command line…]
-                mkosi [options…] {b}coredumpctl{e} [command line…]
+                mkosi [options…] {b}build{e}         [command line…]
+                mkosi [options…] {b}shell{e}         [command line…]
+                mkosi [options…] {b}boot{e}          [nspawn settings…]
+                mkosi [options…] {b}qemu{e}          [qemu parameters…]
+                mkosi [options…] {b}ssh{e}           [command line…]
+                mkosi [options…] {b}journalctl{e}    [command line…]
+                mkosi [options…] {b}coredumpctl{e}   [command line…]
+                mkosi [options…] {b}documentation{e} [manual]
                 mkosi [options…] {b}clean{e}
                 mkosi [options…] {b}serve{e}
                 mkosi [options…] {b}bump{e}
                 mkosi [options…] {b}genkey{e}
-                mkosi [options…] {b}documentation{e}
                 mkosi [options…] {b}help{e}
                 mkosi -h | --help
                 mkosi --version