aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/generate-manpage.nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-25 19:03:13 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-25 19:03:13 +0100
commit36c4d6f59247826dde32ad2e6b5a9471a9a1c911 (patch)
treec07928e4554aaf6622cd1df996fd4fdc1c368f20 /doc/manual/generate-manpage.nix
parent807d963ee8d23e88f09e28365b045d322530c5aa (diff)
Group common options
Diffstat (limited to 'doc/manual/generate-manpage.nix')
-rw-r--r--doc/manual/generate-manpage.nix40
1 files changed, 24 insertions, 16 deletions
diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix
index 30152088d..a563c31f8 100644
--- a/doc/manual/generate-manpage.nix
+++ b/doc/manual/generate-manpage.nix
@@ -38,31 +38,39 @@ let
+ (if def ? doc
then def.doc + "\n\n"
else "")
- + (let s = showFlags def.flags; in
+ + (let s = showOptions def.flags; in
if s != ""
- then "# Flags\n\n${s}"
+ then "# Options\n\n${s}"
else "")
;
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
- showFlags = flags:
- concatStrings
- (map (longName:
- let flag = flags.${longName}; in
- if flag.category or "" != "config"
- then
- " - `--${longName}`"
- + (if flag ? shortName then " / `-${flag.shortName}`" else "")
- + (if flag ? labels then " " + (concatStringsSep " " (map (s: "*${s}*") flag.labels)) else "")
- + " \n"
- + " " + flag.description + "\n\n"
- else "")
- (attrNames flags));
+ showOptions = flags:
+ let
+ categories = sort builtins.lessThan (unique (map (cmd: cmd.category) (attrValues flags)));
+ in
+ concatStrings (map
+ (cat:
+ (if cat != ""
+ then "**${cat}:**\n\n"
+ else "")
+ + concatStrings
+ (map (longName:
+ let
+ flag = flags.${longName};
+ in
+ " - `--${longName}`"
+ + (if flag ? shortName then " / `-${flag.shortName}`" else "")
+ + (if flag ? labels then " " + (concatStringsSep " " (map (s: "*${s}*") flag.labels)) else "")
+ + " \n"
+ + " " + flag.description + "\n\n"
+ ) (attrNames (filterAttrs (n: v: v.category == cat) flags))))
+ categories);
showSynopsis =
{ command, args }:
- "`${command}` [*flags*...] ${concatStringsSep " "
+ "`${command}` [*option*...] ${concatStringsSep " "
(map (arg: "*${arg.label}*" + (if arg ? arity then "" else "...")) args)}\n\n";
processCommand = { command, def, filename }: