Skip to content

Commit

Permalink
fix ShellCheck warnings and add workflow for test
Browse files Browse the repository at this point in the history
ShellCheck previously reported:

```
In please.sh line 123:
  response=(${response[@]})
            ^------------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

In please.sh line 125:
  result=${response[@]::${#response[@]}-1}
         ^-- SC2124: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

In please.sh line 137:
  printf "${lightbulb}${cyan}Command:${black}\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In please.sh line 144:
  printf "${exclamation} ${yellow}What should I do? ${cyan}[use arrow keys to navigate]${black}\n"
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

For more information:
  https://www.shellcheck.net/wiki/SC2124 -- Assigning an array to a string! A...
  https://www.shellcheck.net/wiki/SC2206 -- Quote to prevent word splitting/g...
  https://www.shellcheck.net/wiki/SC2059 -- Don't use variables in the printf...
```

`result=${response[@]::${#response[@]}-1}` is not needed
as `echo "${result}" | jq '.choices[0].message.content' --raw-output`
will anyhow only consider the first element of `response`.

Signed-off-by: Manfred Hanke <[email protected]>
  • Loading branch information
hankem authored and thomas-endres-tng committed Apr 7, 2023
1 parent 4123955 commit b0899b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test Please CLI

on:
push:
branches:
- main
pull_request:

jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
8 changes: 4 additions & 4 deletions please.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,33 @@ explain_command() {
}

perform_openai_request() {
response=$(curl "${openai_invocation_url}/chat/completions" \
IFS=$'\n' read -r -d '' -a response < <(curl "${openai_invocation_url}/chat/completions" \
-s -w "\n%{http_code}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
-d "${payload}" \
--silent)
response=(${response[@]})
httpStatus="${response[${#response[@]}-1]}"
result=${response[@]::${#response[@]}-1}

if [ "${httpStatus}" -ne 200 ]; then
>&2 echo "Error: Received HTTP status ${httpStatus}"
exit 1
else
message=$(echo "${result}" | jq '.choices[0].message.content' --raw-output)
message=$(echo "${response[0]}" | jq '.choices[0].message.content' --raw-output)
echo "${message}"
fi
}

print_option() {
# shellcheck disable=SC2059
printf "${lightbulb}${cyan}Command:${black}\n"
echo " ${command}"
if [ "${explain}" -eq 1 ]; then
echo ""
echo "${explanation}"
fi
echo ""
# shellcheck disable=SC2059
printf "${exclamation} ${yellow}What should I do? ${cyan}[use arrow keys to navigate]${black}\n"
}

Expand Down

0 comments on commit b0899b6

Please sign in to comment.