mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
doc: showOptions
: Simplify code with builtins.groupBy
This makes grouping options by category much nicer. No behavior should be changed.
This commit is contained in:
parent
694810ba34
commit
9c640c1229
1 changed files with 10 additions and 7 deletions
|
@ -1,8 +1,8 @@
|
||||||
let
|
let
|
||||||
inherit (builtins)
|
inherit (builtins)
|
||||||
attrNames attrValues fromJSON listToAttrs mapAttrs
|
attrNames attrValues fromJSON listToAttrs mapAttrs groupBy
|
||||||
concatStringsSep concatMap length lessThan replaceStrings sort;
|
concatStringsSep concatMap length lessThan replaceStrings sort;
|
||||||
inherit (import ./utils.nix) concatStrings optionalString filterAttrs trim squash unique showSettings;
|
inherit (import ./utils.nix) attrsToList concatStrings optionalString filterAttrs trim squash unique showSettings;
|
||||||
in
|
in
|
||||||
|
|
||||||
commandDump:
|
commandDump:
|
||||||
|
@ -87,12 +87,11 @@ let
|
||||||
|
|
||||||
showOptions = allOptions:
|
showOptions = allOptions:
|
||||||
let
|
let
|
||||||
showCategory = cat: ''
|
showCategory = cat: opts: ''
|
||||||
${optionalString (cat != "") "**${cat}:**"}
|
${optionalString (cat != "") "**${cat}:**"}
|
||||||
|
|
||||||
${listOptions (filterAttrs (n: v: v.category == cat) allOptions)}
|
${concatStringsSep "\n" (attrValues (mapAttrs showOption opts))}
|
||||||
'';
|
'';
|
||||||
listOptions = opts: concatStringsSep "\n" (attrValues (mapAttrs showOption opts));
|
|
||||||
showOption = name: option:
|
showOption = name: option:
|
||||||
let
|
let
|
||||||
shortName = optionalString
|
shortName = optionalString
|
||||||
|
@ -106,8 +105,12 @@ let
|
||||||
|
|
||||||
${option.description}
|
${option.description}
|
||||||
'';
|
'';
|
||||||
categories = sort lessThan (unique (map (cmd: cmd.category) (attrValues allOptions)));
|
categories = mapAttrs
|
||||||
in concatStrings (map showCategory categories);
|
(_: listToAttrs)
|
||||||
|
(groupBy
|
||||||
|
(cmd: cmd.value.category)
|
||||||
|
(attrsToList allOptions));
|
||||||
|
in concatStrings (attrValues (mapAttrs showCategory categories));
|
||||||
in squash result;
|
in squash result;
|
||||||
|
|
||||||
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
|
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
|
||||||
|
|
Loading…
Reference in a new issue