aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/build-declarations.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/build-declarations.sh')
-rwxr-xr-xscripts/build-declarations.sh37
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