aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/generate-manpage.nix
diff options
context:
space:
mode:
authorValentin Gagarin <valentin.gagarin@tweag.io>2022-08-26 23:09:19 +0200
committerValentin Gagarin <valentin.gagarin@tweag.io>2022-09-30 01:43:53 +0200
commita85df04fcb2876591ac39d55e920c7cd15411431 (patch)
tree581a9297079544ac3f320a9ca338b68d2834f2d5 /doc/manual/generate-manpage.nix
parent4655563470b59e0ef50a33af003058c2b54db778 (diff)
refactor showOptions
it was quite a pain to manipulate strings just with `builtins`
Diffstat (limited to 'doc/manual/generate-manpage.nix')
-rw-r--r--doc/manual/generate-manpage.nix45
1 files changed, 19 insertions, 26 deletions
diff --git a/doc/manual/generate-manpage.nix b/doc/manual/generate-manpage.nix
index c8290685a..82aae8b46 100644
--- a/doc/manual/generate-manpage.nix
+++ b/doc/manual/generate-manpage.nix
@@ -41,33 +41,26 @@ let
${showOptions def.flags}
'';
- showOptions = flags:
+ showOptions = options:
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);
- squash = string: # squash more than two repeated newlines
- let
- replaced = replaceStrings [ "\n\n\n" ] [ "\n\n" ] string;
- in
- if replaced == string then string else squash replaced;
- in squash ''
+ showCategory = cat: ''
+ ${if cat != "" then "**${cat}:**" else ""}
+
+ ${listOptions (filterAttrs (n: v: v.category == cat) options)}
+ '';
+ listOptions = opts: concatStringsSep "\n" (attrValues (mapAttrs showOption opts));
+ showOption = name: option:
+ let
+ shortName = if option ? shortName then "/ `-${option.shortName}`" else "";
+ labels = if option ? labels then (concatStringsSep " " (map (s: "*${s}*") option.labels)) else "";
+ in trim ''
+ - `--${name}` ${shortName} ${labels}
+
+ ${option.description}
+ '';
+ categories = sort builtins.lessThan (unique (map (cmd: cmd.category) (attrValues options)));
+ in concatStrings (map showCategory categories);
+ in squash ''
> **Warning** \
> This program is **experimental** and its interface is subject to change.