From a68bf15fe6d45588986bb13e9c294f594cb5dd57 Mon Sep 17 00:00:00 2001 From: Valentin Gagarin Date: Fri, 10 Nov 2023 19:22:42 +0100 Subject: [PATCH] backport fix for the `--help` output --- doc/manual/generate-manpage.nix | 21 ++++++++++++--------- doc/manual/local.mk | 4 ++-- doc/manual/utils.nix | 4 ++-- src/nix/main.cc | 3 ++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix index bc4d2c5bc..0b49fac6d 100644 --- a/doc/manual/generate-manpage.nix +++ b/doc/manual/generate-manpage.nix @@ -5,7 +5,7 @@ let inherit (import ./utils.nix) concatStrings optionalString filterAttrs trim squash unique showSettings; in -commandDump: +inlineHTML: commandDump: let @@ -30,7 +30,7 @@ let ${maybeSubcommands} - ${maybeDocumentation} + ${maybeStoreDocs} ${maybeOptions} ''; @@ -70,7 +70,7 @@ let * [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description} ''; - maybeDocumentation = optionalString + maybeStoreDocs = optionalString (details ? doc) (replaceStrings ["@stores@"] [storeDocs] details.doc); @@ -91,17 +91,20 @@ let listOptions = opts: concatStringsSep "\n" (attrValues (mapAttrs showOption opts)); showOption = name: option: let + result = trim '' + - ${item} + ${option.description} + ''; + item = if inlineHTML + then ''[`--${name}`](#opt-${name}) ${shortName} ${labels}'' + else "`--${name}` ${shortName} ${labels}"; shortName = optionalString (option ? shortName) ("/ `-${option.shortName}`"); labels = optionalString (option ? labels) (concatStringsSep " " (map (s: "*${s}*") option.labels)); - in trim '' - - [`--${name}`](#opt-${name}) ${shortName} ${labels} - - ${option.description} - ''; + in result; categories = sort lessThan (unique (map (cmd: cmd.category) (attrValues allOptions))); in concatStrings (map showCategory categories); in squash result; @@ -162,7 +165,7 @@ let **Settings**: - ${showSettings { useAnchors = false; } settings} + ${showSettings { inherit inlineHTML; } settings} ''; in concatStrings (attrValues (mapAttrs showStore commandInfo.stores)); diff --git a/doc/manual/local.mk b/doc/manual/local.mk index abdfd6a62..826783675 100644 --- a/doc/manual/local.mk +++ b/doc/manual/local.mk @@ -98,12 +98,12 @@ $(d)/src/SUMMARY.md: $(d)/src/SUMMARY.md.in $(d)/src/command-ref/new-cli $(d)/sr $(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/utils.nix $(d)/generate-manpage.nix $(bindir)/nix @rm -rf $@ $@.tmp - $(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix (builtins.readFile $<)' + $(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix true (builtins.readFile $<)' @mv $@.tmp $@ $(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/utils.nix $(d)/src/command-ref/conf-file-prefix.md $(d)/src/command-ref/experimental-features-shortlist.md $(bindir)/nix @cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp - $(trace-gen) $(nix-eval) --expr '(import doc/manual/utils.nix).showSettings { useAnchors = true; } (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp; + $(trace-gen) $(nix-eval) --expr '(import doc/manual/utils.nix).showSettings { inlineHTML = true; } (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp; @mv $@.tmp $@ $(d)/nix.json: $(bindir)/nix diff --git a/doc/manual/utils.nix b/doc/manual/utils.nix index 9043dd8cd..193c1efc0 100644 --- a/doc/manual/utils.nix +++ b/doc/manual/utils.nix @@ -44,10 +44,10 @@ rec { optionalString = cond: string: if cond then string else ""; - showSetting = { useAnchors }: name: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }: + showSetting = { inlineHTML }: name: { description, documentDefault, defaultValue, aliases, value, experimentalFeature }: let result = squash '' - - ${if useAnchors + - ${if inlineHTML then ''[`${name}`](#conf-${name})'' else ''`${name}`''} diff --git a/src/nix/main.cc b/src/nix/main.cc index d05bac68e..eb510eecc 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -218,7 +218,8 @@ static void showHelp(std::vector subcommand, NixArgs & toplevel) vDump->mkString(toplevel.dumpCli()); auto vRes = state.allocValue(); - state.callFunction(*vGenerateManpage, *vDump, *vRes, noPos); + state.callFunction(*vGenerateManpage, state.getBuiltin("false"), *vRes, noPos); + state.callFunction(*vRes, *vDump, *vRes, noPos); auto attr = vRes->attrs->get(state.symbols.create(mdName + ".md")); if (!attr)