Skip to content

Commit

Permalink
chore: improve Argcfile.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed May 19, 2024
1 parent 03c4b69 commit e6642b5
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions Argcfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ build-bin() {
# @option --names-file=functions.txt Path to a file containing function filenames, one per line.
# @arg funcs*[`_choice_func`] The function filenames
build-declarations-json() {
set +e
if [[ "${#argc_funcs[@]}" -gt 0 ]]; then
names=("${argc_funcs[@]}" )
elif [[ -f "$argc_names_file" ]]; then
Expand All @@ -104,13 +103,10 @@ build-declarations-json() {
not_found_funcs+=("$name")
continue;
fi
json_data="$("build-single-declaration" "$name")"
status=$?
if [ $status -eq 0 ]; then
json_list+=("$json_data")
else
json_data="$("build-single-declaration" "$name")" || {
build_failed_funcs+=("$name")
fi
}
json_list+=("$json_data")
done
if [[ -n "$not_found_funcs" ]]; then
_die "error: not found functions: ${not_found_funcs[*]}"
Expand Down Expand Up @@ -139,26 +135,19 @@ build-single-declaration() {
# @cmd List functions that can be put into functions.txt
# Examples:
# argc --list-functions > functions.txt
# argc --list-functions --write
# argc --list-functions search_duckduckgo.sh >> functions.txt
# @flag -w --write Output to functions.txt
# @arg funcs*[`_choice_func`] The function filenames, list all available functions if not provided
list-functions() {
if [[ -n "$argc_write" ]]; then
_choice_func > functions.txt
echo "Write functions.txt"
else
_choice_func
fi
_choice_func
}

# @cmd Test the project
# @meta require-tools node,python,ruby
test() {
names_file=functions.txt.test
argc list-functions > "$names_file"
argc build --names-file "$names_file"
func_names_file=functions.txt.test
argc list-functions > "$func_names_file"
argc build --names-file "$func_names_file"
argc test-call-functions
rm -rf "$func_names_file"
}


Expand All @@ -170,17 +159,23 @@ test-call-functions() {
"./bin/may_execute_command$ext" --command 'echo "bash works"'
argc call may_execute_command.sh --command 'echo "bash works"'

export LLM_FUNCTION_DATA='{"code":"console.log(\"javascript works\")"}'
"./bin/may_execute_js_code$ext"
argc call may_execute_js_code.js
if command -v node &> /dev/null; then
export LLM_FUNCTION_DATA='{"code":"console.log(\"javascript works\")"}'
"./bin/may_execute_js_code$ext"
argc call may_execute_js_code.js
fi

export LLM_FUNCTION_DATA='{"code":"print(\"python works\")"}'
"./bin/may_execute_py_code$ext"
argc call may_execute_py_code.py
if command -v python &> /dev/null; then
export LLM_FUNCTION_DATA='{"code":"print(\"python works\")"}'
"./bin/may_execute_py_code$ext"
argc call may_execute_py_code.py
fi

export LLM_FUNCTION_DATA='{"code":"puts \"ruby works\""}'
"./bin/may_execute_rb_code$ext"
argc call may_execute_rb_code.rb
if command -v ruby &> /dev/null; then
export LLM_FUNCTION_DATA='{"code":"puts \"ruby works\""}'
"./bin/may_execute_rb_code$ext"
argc call may_execute_rb_code.rb
fi
}

# @cmd Install this repo to aichat functions_dir
Expand Down Expand Up @@ -298,7 +293,10 @@ _is_win() {
_choice_func() {
for item in "${LANG_CMDS[@]}"; do
lang="${item%:*}"
ls -1 $lang | grep "\.$lang$"
cmd="${item#*:}"
if command -v "$cmd" &> /dev/null; then
ls -1 $lang | grep "\.$lang$"
fi
done
}

Expand Down

0 comments on commit e6642b5

Please sign in to comment.