diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-07 21:36:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-07 21:36:34 +0800 |
| commit | 63df67acea19b3708d34ef3b656c1b784c2a72f4 (patch) | |
| tree | 740ff6c276131898e59bf1495abc238d3fdfb9a7 /scripts/build-declarations.sh | |
| parent | e1d895cc9abb0f7ffac8acc043746cbe2e5f4fe1 (diff) | |
| download | llm-functions-docker-63df67acea19b3708d34ef3b656c1b784c2a72f4.tar.gz | |
refactor: numerous improvements (#32)
Diffstat (limited to 'scripts/build-declarations.sh')
| -rwxr-xr-x | scripts/build-declarations.sh | 37 |
1 files changed, 30 insertions, 7 deletions
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 |
