use more self-explanatory names

This commit is contained in:
Valentin Gagarin 2022-08-27 03:25:12 +02:00
parent 61188cb820
commit 70eea97742

View file

@ -5,7 +5,7 @@ with import ./utils.nix;
let let
showCommand = { command, def, filename }: showCommand = { command, details, filename }:
let let
result = '' result = ''
> **Warning** \ > **Warning** \
@ -13,11 +13,11 @@ let
# Name # Name
`${command}` - ${def.description} `${command}` - ${details.description}
# Synopsis # Synopsis
${showSynopsis command def.args} ${showSynopsis command details.args}
${maybeSubcommands} ${maybeSubcommands}
@ -32,7 +32,7 @@ let
in '' in ''
`${command}` [*option*...] ${arguments} `${command}` [*option*...] ${arguments}
''; '';
maybeSubcommands = if def ? commands && def.commands != {} maybeSubcommands = if details ? commands && details.commands != {}
then '' then ''
where *subcommand* is one of the following: where *subcommand* is one of the following:
@ -41,23 +41,23 @@ let
else ""; else "";
subcommands = if length categories > 1 subcommands = if length categories > 1
then listCategories then listCategories
else listSubcommands def.commands; else listSubcommands details.commands;
categories = sort (x: y: x.id < y.id) (unique (map (cmd: cmd.category) (attrValues def.commands))); categories = sort (x: y: x.id < y.id) (unique (map (cmd: cmd.category) (attrValues details.commands)));
listCategories = concatStrings (map showCategory categories); listCategories = concatStrings (map showCategory categories);
showCategory = cat: '' showCategory = cat: ''
**${toString cat.description}:** **${toString cat.description}:**
${listSubcommands (filterAttrs (n: v: v.category == cat) def.commands)} ${listSubcommands (filterAttrs (n: v: v.category == cat) details.commands)}
''; '';
listSubcommands = cmds: concatStrings (attrValues (mapAttrs showSubcommand cmds)); listSubcommands = cmds: concatStrings (attrValues (mapAttrs showSubcommand cmds));
showSubcommand = name: subcmd: '' showSubcommand = name: subcmd: ''
* [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description} * [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description}
''; '';
maybeDocumentation = if def ? doc then def.doc else ""; maybeDocumentation = if details ? doc then details.doc else "";
maybeOptions = if def.flags == {} then "" else '' maybeOptions = if details.flags == {} then "" else ''
# Options # Options
${showOptions def.flags} ${showOptions details.flags}
''; '';
showOptions = options: showOptions = options:
let let
@ -82,17 +82,29 @@ let
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name; appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
processCommand = { command, def, filename }: processCommand = { command, details, filename }:
[ { name = filename + ".md"; value = showCommand { inherit command def filename; }; inherit command; } ] let
++ concatMap cmd = {
(name: processCommand { inherit command;
filename = appendName filename name; name = filename + ".md";
command = command + " " + name; value = showCommand { inherit command details filename; };
def = def.commands.${name}; };
}) subcommand = subCmd: processCommand {
(attrNames def.commands or {}); command = command + " " + subCmd;
details = details.commands.${subCmd};
filename = appendName filename subCmd;
};
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});
manpages = processCommand { filename = "nix"; command = "nix"; def = builtins.fromJSON command; }; manpages = processCommand {
summary = concatStrings (map (manpage: " - [${manpage.command}](command-ref/new-cli/${manpage.name})\n") manpages); command = "nix";
in details = builtins.fromJSON command;
(listToAttrs manpages) // { "SUMMARY.md" = summary; } filename = "nix";
};
tableOfContents = let
showEntry = page:
" - [${page.command}](command-ref/new-cli/${page.name})";
in concatStringsSep "\n" (map showEntry manpages);
in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }