lol

Merge pull request #200646 from hercules-ci/options-markdown-and-errors

`nixosOptionsDoc`: add `markdownByDefault`, error handling

authored by

Robert Hensing and committed by
GitHub
833f9d5e 926e2305

+22 -8
+3
nixos/lib/make-options-doc/default.nix
··· 40 40 # `false`, and a different renderer may be used with different bugs and performance 41 41 # characteristics but (hopefully) indistinguishable output. 42 42 , allowDocBook ? true 43 + # whether lib.mdDoc is required for descriptions to be read as markdown. 44 + , markdownByDefault ? false 43 45 }: 44 46 45 47 let ··· 152 154 python ${./mergeJSON.py} \ 153 155 ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \ 154 156 ${lib.optionalString (! allowDocBook) "--error-on-docbook"} \ 157 + ${lib.optionalString markdownByDefault "--markdown-by-default"} \ 155 158 $baseJSON $options \ 156 159 > $dst/options.json 157 160
+19 -8
nixos/lib/make-options-doc/mergeJSON.py
··· 201 201 return option[key]['_type'] == typ 202 202 203 203 for (name, option) in options.items(): 204 - if optionIs(option, 'description', 'mdDoc'): 205 - option['description'] = convertString(name, option['description']['text']) 206 - if optionIs(option, 'example', 'literalMD'): 207 - docbook = convertString(name, option['example']['text']) 208 - option['example'] = { '_type': 'literalDocBook', 'text': docbook } 209 - if optionIs(option, 'default', 'literalMD'): 210 - docbook = convertString(name, option['default']['text']) 211 - option['default'] = { '_type': 'literalDocBook', 'text': docbook } 204 + try: 205 + if optionIs(option, 'description', 'mdDoc'): 206 + option['description'] = convertString(name, option['description']['text']) 207 + elif markdownByDefault: 208 + option['description'] = convertString(name, option['description']) 209 + 210 + if optionIs(option, 'example', 'literalMD'): 211 + docbook = convertString(name, option['example']['text']) 212 + option['example'] = { '_type': 'literalDocBook', 'text': docbook } 213 + if optionIs(option, 'default', 'literalMD'): 214 + docbook = convertString(name, option['default']['text']) 215 + option['default'] = { '_type': 'literalDocBook', 'text': docbook } 216 + except Exception as e: 217 + raise Exception(f"Failed to render option {name}: {str(e)}") 218 + 212 219 213 220 return options 214 221 215 222 warningsAreErrors = False 216 223 errorOnDocbook = False 224 + markdownByDefault = False 217 225 optOffset = 0 218 226 for arg in sys.argv[1:]: 219 227 if arg == "--warnings-are-errors": ··· 222 230 if arg == "--error-on-docbook": 223 231 optOffset += 1 224 232 errorOnDocbook = True 233 + if arg == "--markdown-by-default": 234 + optOffset += 1 235 + markdownByDefault = True 225 236 226 237 options = pivot(json.load(open(sys.argv[1 + optOffset], 'r'))) 227 238 overrides = pivot(json.load(open(sys.argv[2 + optOffset], 'r')))