aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/generate-manpage.nix
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-01 15:15:32 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-01 15:15:32 -0400
commitf7f44f7c96eaa65b096e1448591e5790a58f3ad9 (patch)
tree1fdcfbbc31a1496075dd6796043c75426ee8da1c /doc/manual/generate-manpage.nix
parent5abd643c6d10f2cfa6e26652a9688a0263310094 (diff)
parentaa99005004bccc9be506a2a2f162f78bad4bcb41 (diff)
Merge commit 'aa99005004bccc9be506a2a2f162f78bad4bcb41' into ca-drv-exotic
Diffstat (limited to 'doc/manual/generate-manpage.nix')
-rw-r--r--doc/manual/generate-manpage.nix41
1 files changed, 35 insertions, 6 deletions
diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix
index 8c7c4d358..86f2ca567 100644
--- a/doc/manual/generate-manpage.nix
+++ b/doc/manual/generate-manpage.nix
@@ -1,4 +1,4 @@
-{ toplevel }:
+cliDumpStr:
with builtins;
with import ./utils.nix;
@@ -7,6 +7,7 @@ let
showCommand = { command, details, filename, toplevel }:
let
+
result = ''
> **Warning** \
> This program is **experimental** and its interface is subject to change.
@@ -25,6 +26,7 @@ let
${maybeOptions}
'';
+
showSynopsis = command: args:
let
showArgument = arg: "*${arg.label}*" + (if arg ? arity then "" else "...");
@@ -32,6 +34,7 @@ let
in ''
`${command}` [*option*...] ${arguments}
'';
+
maybeSubcommands = if details ? commands && details.commands != {}
then ''
where *subcommand* is one of the following:
@@ -39,26 +42,38 @@ let
${subcommands}
''
else "";
+
subcommands = if length categories > 1
then listCategories
else listSubcommands details.commands;
+
categories = sort (x: y: x.id < y.id) (unique (map (cmd: cmd.category) (attrValues details.commands)));
+
listCategories = concatStrings (map showCategory categories);
+
showCategory = cat: ''
**${toString cat.description}:**
${listSubcommands (filterAttrs (n: v: v.category == cat) details.commands)}
'';
+
listSubcommands = cmds: concatStrings (attrValues (mapAttrs showSubcommand cmds));
+
showSubcommand = name: subcmd: ''
* [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description}
'';
- maybeDocumentation = if details ? doc then details.doc else "";
+
+ maybeDocumentation =
+ if details ? doc
+ then replaceStrings ["@stores@"] [storeDocs] details.doc
+ else "";
+
maybeOptions = if details.flags == {} then "" else ''
# Options
${showOptions details.flags toplevel.flags}
'';
+
showOptions = options: commonOptions:
let
allOptions = options // commonOptions;
@@ -98,13 +113,13 @@ let
};
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});
- parsedToplevel = builtins.fromJSON toplevel;
-
+ cliDump = builtins.fromJSON cliDumpStr;
+
manpages = processCommand {
command = "nix";
- details = parsedToplevel;
+ details = cliDump.args;
filename = "nix";
- toplevel = parsedToplevel;
+ toplevel = cliDump.args;
};
tableOfContents = let
@@ -112,4 +127,18 @@ let
" - [${page.command}](command-ref/new-cli/${page.name})";
in concatStringsSep "\n" (map showEntry manpages) + "\n";
+ storeDocs =
+ let
+ showStore = name: { settings, doc }:
+ ''
+ ## ${name}
+
+ ${doc}
+
+ **Settings**:
+
+ ${showSettings { useAnchors = false; } settings}
+ '';
+ in concatStrings (attrValues (mapAttrs showStore cliDump.stores));
+
in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }