refactor: numerous improvements (#32)

This commit is contained in:
sigoden
2024-06-07 21:36:34 +08:00
committed by GitHub
parent e1d895cc9a
commit 63df67acea
11 changed files with 159 additions and 115 deletions
+30 -7
View File
@@ -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")])
}]'
def parse_declaration:
{
name: (.name | sub("-"; "_"; "g")),
description: .describe,
parameters: parse_parameter([.flag_options[] | select(.id != "help" and .id != "version")])
};
[
.[] | parse_declaration
]'
}
main "$@"