|
47 | 47 | in |
48 | 48 | map (p: repack (unpack p)); |
49 | 49 |
|
| 50 | + mkUrl = root: path: "${root.url}/tree/${root.branch}/${path}"; |
| 51 | + |
50 | 52 | # Transforms a module path into a (path, url) tuple where path is relative |
51 | 53 | # to the repo root, and URL points to an online view of the module. |
52 | 54 | mkDeclaration = |
|
69 | 71 | else |
70 | 72 | rec { |
71 | 73 | path = removePrefix root.prefix decl; |
72 | | - url = "${root.url}/tree/${root.branch}/${path}"; |
| 74 | + url = mkUrl root path; |
73 | 75 | }; |
74 | 76 |
|
75 | 77 | # Sort modules and put "enable" and "package" declarations first. |
|
80 | 82 | compareWithPrio = pred: cmp: splitByAndCompare pred compare cmp; |
81 | 83 | moduleCmp = compareWithPrio isEnable (compareWithPrio isPackage compare); |
82 | 84 | in |
83 | | - compareLists moduleCmp a.loc b.loc < 0; |
| 85 | + compareLists moduleCmp (map toString a.loc) (map toString b.loc) < 0; |
84 | 86 |
|
85 | 87 | # Replace functions by the string <function> |
86 | 88 | substFunction = x: |
@@ -114,11 +116,22 @@ let |
114 | 116 | ) |
115 | 117 | ); |
116 | 118 |
|
| 119 | + inherit (import ../nix/commands/lib.nix { inherit pkgs; }) mkLocSuffix nestedOptionsType flatOptionsType; |
| 120 | + |
117 | 121 | # TODO: display values like TOML instead. |
118 | 122 | toMarkdown = optionsDocs: |
119 | 123 | let |
120 | | - optionsDocsPartitioned = partition (opt: head opt.loc != "_module") optionsDocs; |
121 | | - |
| 124 | + optionsDocsPartitionedIsMain = partition (opt: head opt.loc != "_module") optionsDocs; |
| 125 | + nixOnlyLocPrefix = [ "commands" "<name>" ]; |
| 126 | + optionsDocsPartitionedIsNixOnly = partition (opt: (take 2 opt.loc) == nixOnlyLocPrefix) optionsDocsPartitionedIsMain.right; |
| 127 | + nixOnly = optionsDocsPartitionedIsNixOnly.right; |
| 128 | + nixOnlyPartitionedIsTop = partition (opt: opt.loc == nixOnlyLocPrefix ++ [ "*" ]) nixOnly; |
| 129 | + nixOnlyPartitionedHasSuffix = partition (opt: ("${last opt.loc}" == "${mkLocSuffix nestedOptionsType.name}")) nixOnlyPartitionedIsTop.wrong; |
| 130 | + nixOnlyOrdered = nixOnlyPartitionedIsTop.right ++ nixOnlyPartitionedHasSuffix.right ++ nixOnlyPartitionedHasSuffix.wrong; |
| 131 | + nixAndTOMLOrdered = optionsDocsPartitionedIsNixOnly.wrong; |
| 132 | + nixExtra = optionsDocsPartitionedIsMain.wrong; |
| 133 | + concatOpts = opts: (concatStringsSep "\n\n" (map optToMd opts)); |
| 134 | + |
122 | 135 | # TODO: handle opt.relatedPackages. What is it for? |
123 | 136 | optToMd = opt: |
124 | 137 | let heading = (lib.showOption (filter isString opt.loc)) + (concatStrings (filter (x: !(isString x)) opt.loc)); in |
@@ -165,13 +178,30 @@ let |
165 | 178 | opt.declarations |
166 | 179 | ) |
167 | 180 | ) |
168 | | - + "\n" |
169 | 181 | ; |
170 | 182 | doc = [ |
171 | | - "## Options\n" |
172 | | - (concatStringsSep "\n" (map optToMd optionsDocsPartitioned.right)) |
173 | | - "## Extra options\n" |
174 | | - (concatStringsSep "\n" (map optToMd optionsDocsPartitioned.wrong)) |
| 183 | + "# Options\n" |
| 184 | + "## Available only in `Nix`\n" |
| 185 | + ( |
| 186 | + let |
| 187 | + root = head cfg.roots; |
| 188 | + pathExamples = "nix/commands/examples.nix"; |
| 189 | + pathExamplesReal = ../${pathExamples}; |
| 190 | + pathCommandsLib = "tests/extra/commands.lib.nix"; |
| 191 | + pathCommandsLibReal = ../${pathCommandsLib}; |
| 192 | + mkLink = path: "[link](${mkUrl root path})"; |
| 193 | + in |
| 194 | + assert lib.assertMsg (lib.pathExists pathExamplesReal) "Path `${pathExamplesReal} doesn't exist.`"; |
| 195 | + assert lib.assertMsg (lib.pathExists pathCommandsLibReal) "Path `${pathCommandsLibReal} doesn't exist.`"; |
| 196 | + '' |
| 197 | + See how `commands.<name>` (${mkLink pathExamples}) maps to `commands.*` (${mkLink pathCommandsLib}). |
| 198 | + '' |
| 199 | + ) |
| 200 | + (concatOpts nixOnlyOrdered) |
| 201 | + "## Available in `Nix` and `TOML`\n" |
| 202 | + (concatOpts nixAndTOMLOrdered) |
| 203 | + "## Extra options available only in `Nix`\n" |
| 204 | + (concatOpts nixExtra) |
175 | 205 | ]; |
176 | 206 | in |
177 | 207 | concatStringsSep "\n" doc; |
|
0 commit comments