From fea3a76ddfecfc8c55fed17fb181a00c06030f91 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Tue, 16 Apr 2024 21:37:25 +0200 Subject: [PATCH] add parser for 22.11 --- scripts/parse_options-json.rb | 41 +++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/parse_options-json.rb b/scripts/parse_options-json.rb index 74a240a..3e160ba 100644 --- a/scripts/parse_options-json.rb +++ b/scripts/parse_options-json.rb @@ -13,24 +13,41 @@ p ENV['HM_RELEASE'] in_file = File.read("./result/share/doc/home-manager/options.json") parsed = JSON.parse(in_file) +def isLiteralExpression(val, key) + if val.key? key and val[key].instance_of? Hash and val[key].key? "_type" and val[key]['_type'] == 'literalExpression' + true + else + false + end +end + +def getValFor(val, key) + if isLiteralExpression(val, key) + val[key]['text'] + elsif val.key? key + val[key] + else + "" + end +end + +def parseVal2211(val) + val['example'] = getValFor(val, 'example') + val['default'] = getValFor(val, 'default') + + val +end + +def parseVal2305(val) +end + options_arr = [] parsed.each do | name, val | next if name == '_module.args' val['title'] = name - - if val.key? "example" - val['example'] = val['example']['text'] - else - val['example'] = "" - end - - if val.key? "default" - val['default'] = val['default']['text'] - else - val['default'] = "" - end + val = parseVal2211(val) options_arr << val end