diff options
Diffstat (limited to 'scripts/build-declarations.sh')
| -rwxr-xr-x | scripts/build-declarations.sh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/build-declarations.sh b/scripts/build-declarations.sh new file mode 100755 index 0000000..1f5786a --- /dev/null +++ b/scripts/build-declarations.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +argc --argc-export "$1" | \ +jq -r ' + def parse_description(flag_option): + if flag_option.describe == "" then + {} + else + { "description": flag_option.describe } + end; + + def parse_enum(flag_option): + if flag_option.choice.type == "Values" then + { "enum": flag_option.choice.data } + else + {} + end; + + def parse_property(flag_option): + [ + { condition: (flag_option.flag == true), result: { type: "boolean" } }, + { condition: (flag_option.multiple_occurs == true), result: { type: "array", items: { type: "string" } } }, + { condition: (flag_option.notations[0] == "INT"), result: { type: "integer" } }, + { condition: (flag_option.notations[0] == "NUM"), result: { type: "number" } }, + { condition: true, result: { type: "string" } } ] + | map(select(.condition) | .result) | first + | (. + parse_description(flag_option)) + | (. + parse_enum(flag_option)) + ; + + + def parse_parameter(flag_options): + { + type: "object", + properties: (reduce flag_options[] as $item ({}; . + { ($item.id | sub("-"; "_"; "g")): parse_property($item) })), + required: [flag_options[] | select(.required == true) | .id | sub("-"; "_"; "g")], + }; + + [{ + name: (.name | sub("-"; "_"; "g")), + description: .describe, + parameters: parse_parameter([.flag_options[] | select(.id != "help" and .id != "version")]) + }]'
\ No newline at end of file |
