mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
Merge pull request #9028 from Ericson2314/nix3-config-options
Misc options rendering adjustments
This commit is contained in:
commit
728767db03
2 changed files with 20 additions and 13 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:
|
||||||
|
@ -75,25 +75,27 @@ let
|
||||||
(details ? doc)
|
(details ? doc)
|
||||||
(replaceStrings ["@stores@"] [storeDocs] details.doc);
|
(replaceStrings ["@stores@"] [storeDocs] details.doc);
|
||||||
|
|
||||||
maybeOptions = optionalString (details.flags != {}) ''
|
maybeOptions = let
|
||||||
|
allVisibleOptions = filterAttrs
|
||||||
|
(_: o: ! o.hiddenCategory)
|
||||||
|
(details.flags // toplevel.flags);
|
||||||
|
in optionalString (allVisibleOptions != {}) ''
|
||||||
# Options
|
# Options
|
||||||
|
|
||||||
${showOptions details.flags toplevel.flags}
|
${showOptions allVisibleOptions}
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
|
> See [`man nix.conf`](@docroot@/command-ref/conf-file.md#command-line-flags) for overriding configuration settings with command line flags.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
showOptions = options: commonOptions:
|
showOptions = allOptions:
|
||||||
let
|
let
|
||||||
allOptions = options // commonOptions;
|
showCategory = cat: opts: ''
|
||||||
showCategory = cat: ''
|
${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
|
||||||
|
@ -107,8 +109,13 @@ let
|
||||||
|
|
||||||
${option.description}
|
${option.description}
|
||||||
'';
|
'';
|
||||||
categories = sort lessThan (unique (map (cmd: cmd.category) (attrValues allOptions)));
|
categories = mapAttrs
|
||||||
in concatStrings (map showCategory categories);
|
# Convert each group from a list of key-value pairs back to an attrset
|
||||||
|
(_: 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;
|
||||||
|
|
|
@ -236,7 +236,7 @@ nlohmann::json Args::toJSON()
|
||||||
|
|
||||||
for (auto & [name, flag] : longFlags) {
|
for (auto & [name, flag] : longFlags) {
|
||||||
auto j = nlohmann::json::object();
|
auto j = nlohmann::json::object();
|
||||||
if (hiddenCategories.count(flag->category)) continue;
|
j["hiddenCategory"] = hiddenCategories.count(flag->category) > 0;
|
||||||
if (flag->aliases.count(name)) continue;
|
if (flag->aliases.count(name)) continue;
|
||||||
if (flag->shortName)
|
if (flag->shortName)
|
||||||
j["shortName"] = std::string(1, flag->shortName);
|
j["shortName"] = std::string(1, flag->shortName);
|
||||||
|
|
Loading…
Reference in a new issue