From: Jörg Behrmann Date: Fri, 30 Aug 2024 09:13:39 +0000 (+0200) Subject: doc: make documentation command take an argument X-Git-Tag: v25~311^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e366093b1ce1c7741973c02717c582065a3da04b;p=thirdparty%2Fmkosi.git doc: make documentation command take an argument 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 8a94335c5..9064ccf4f 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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 diff --git a/mkosi/config.py b/mkosi/config.py index 71adc9e61..001300c1a 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -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