From 63df67acea19b3708d34ef3b656c1b784c2a72f4 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 7 Jun 2024 21:36:34 +0800 Subject: refactor: numerous improvements (#32) --- scripts/build-declarations.sh | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'scripts/build-declarations.sh') diff --git a/scripts/build-declarations.sh b/scripts/build-declarations.sh index 1f5786a..6ac2cf4 100755 --- a/scripts/build-declarations.sh +++ b/scripts/build-declarations.sh @@ -1,7 +1,23 @@ #!/usr/bin/env bash -argc --argc-export "$1" | \ -jq -r ' +main() { + scriptfile="$1" + is_tool=false + if [[ "$(dirname "$scriptfile")" == tools ]]; then + is_tool=true + fi + if [[ "$is_tool" == "true" ]]; then + expr='[.]' + else + expr='.subcommands' + fi + argc --argc-export "$scriptfile" | \ + jq "$expr" | \ + build_declarations +} + +build_declarations() { + jq -r ' def parse_description(flag_option): if flag_option.describe == "" then {} @@ -36,8 +52,15 @@ jq -r ' 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 + def parse_declaration: + { + name: (.name | sub("-"; "_"; "g")), + description: .describe, + parameters: parse_parameter([.flag_options[] | select(.id != "help" and .id != "version")]) + }; + [ + .[] | parse_declaration + ]' +} + +main "$@" \ No newline at end of file -- cgit v1.2.3