Skip to content

Commit

Permalink
💥 renamed LAST_RETURNED.. to RETURNED..
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Apr 26, 2024
1 parent c6f3522 commit 0979268
Show file tree
Hide file tree
Showing 41 changed files with 505 additions and 505 deletions.
2 changes: 1 addition & 1 deletion docs/create-new-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Valet has a function to parse the expected options and arguments directly into v
```bash
local myOption myArgument
# parse the arguments of the command
core::parseArguments "$@" && eval "${LAST_RETURNED_VALUE}"
core::parseArguments "$@" && eval "${RETURNED_VALUE}"
# check if we need to fail because there was some inputs errors or if we need to just display the help
core::checkParseResults "${help:-}" "${parsingErrors:-}"

Expand Down
6 changes: 3 additions & 3 deletions examples.d/showcase/showcase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ examples:
---"
function showcaseCommand1() {
local -a more
core::parseArguments "$@" && eval "${LAST_RETURNED_VALUE}"
core::parseArguments "$@" && eval "${RETURNED_VALUE}"
core::checkParseResults "${help:-}" "${parsingErrors:-}"

log::info "First argument: ${firstArg:-}."
Expand Down Expand Up @@ -80,7 +80,7 @@ description: |-
An hello world command.
---"
function helloWorld() {
core::parseArguments "$@" && eval "${LAST_RETURNED_VALUE}"
core::parseArguments "$@" && eval "${RETURNED_VALUE}"
core::checkParseResults "${help:-}" "${parsingErrors:-}"

echo "Hello world!"
Expand All @@ -103,7 +103,7 @@ description: |-
If so, it will require the user to enter the sudo password and use sudo inside the command
---"
function showCaseSudo() {
core::parseArguments "$@" && eval "${LAST_RETURNED_VALUE}"
core::parseArguments "$@" && eval "${RETURNED_VALUE}"
core::checkParseResults "${help:-}" "${parsingErrors:-}"

${SUDO} whoami
Expand Down
16 changes: 8 additions & 8 deletions tests.d/1000-core-functions/00.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ There were 2 new lines before this."

echo "→ string::wrapText \"\${shortText}\" 30"
echo "------------------------------"
string::wrapText "${shortText}" 30 && echo "${LAST_RETURNED_VALUE}"
string::wrapText "${shortText}" 30 && echo "${RETURNED_VALUE}"
endTest "Wrapping text at column 30 with no padding" 0

echo "→ string::wrapText \"\${shortText}\" 90 4 false"
echo "------------------------------------------------------------------------------------------"
string::wrapText "${shortText}" 90 4 false && echo "${LAST_RETURNED_VALUE}"
string::wrapText "${shortText}" 90 4 false && echo "${RETURNED_VALUE}"
endTest "Wrapping text at column 90 with padding of 4 on new lines" 0

echo "→ string::wrapText \"\${shortText}\" 90 2 true"
echo "------------------------------------------------------------------------------------------"
string::wrapText "${shortText}" 90 2 true && echo "${LAST_RETURNED_VALUE}"
string::wrapText "${shortText}" 90 2 true && echo "${RETURNED_VALUE}"
endTest "Wrapping text at column 90 with padding of 2 on all lines" 0
}

Expand All @@ -39,27 +39,27 @@ function testArray::fuzzyFilter() {
echo
echo "→ array::fuzzyFilter evle lines"
array::fuzzyFilter "evle" lines
declare -p LAST_RETURNED_ARRAY LAST_RETURNED_ARRAY2 LAST_RETURNED_ARRAY3
declare -p RETURNED_ARRAY RETURNED_ARRAY2 RETURNED_ARRAY3

echo
echo "→ array::fuzzyFilter SC2 lines"
array::fuzzyFilter "SC2" lines
declare -p LAST_RETURNED_ARRAY LAST_RETURNED_ARRAY2 LAST_RETURNED_ARRAY3
declare -p RETURNED_ARRAY RETURNED_ARRAY2 RETURNED_ARRAY3

echo
echo "→ array::fuzzyFilter u lines"
array::fuzzyFilter "u" lines
declare -p LAST_RETURNED_ARRAY LAST_RETURNED_ARRAY2 LAST_RETURNED_ARRAY3
declare -p RETURNED_ARRAY RETURNED_ARRAY2 RETURNED_ARRAY3

echo
echo "→ array::fuzzyFilter seLf lines"
array::fuzzyFilter "seLf" lines
declare -p LAST_RETURNED_ARRAY LAST_RETURNED_ARRAY2 LAST_RETURNED_ARRAY3
declare -p RETURNED_ARRAY RETURNED_ARRAY2 RETURNED_ARRAY3

echo
echo "→ array::fuzzyFilter nomatch lines"
array::fuzzyFilter "nomatch" lines
declare -p LAST_RETURNED_ARRAY LAST_RETURNED_ARRAY2 LAST_RETURNED_ARRAY3
declare -p RETURNED_ARRAY RETURNED_ARRAY2 RETURNED_ARRAY3

unset lines

Expand Down
30 changes: 15 additions & 15 deletions tests.d/1000-core-functions/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ Exit code: `0`
declare -a lines=([0]="this is a word" [1]="very unbelievable" [2]="unbelievable" [3]="self mock1" [4]="self mock2" [5]="ublievable")
→ array::fuzzyFilter evle lines
declare -a LAST_RETURNED_ARRAY=([0]="very unbelievable" [1]="unbelievable" [2]="ublievable")
declare -a LAST_RETURNED_ARRAY2=([0]="1" [1]="3" [2]="4")
declare -a LAST_RETURNED_ARRAY3=([0]="0" [1]="0" [2]="0")
declare -a RETURNED_ARRAY=([0]="very unbelievable" [1]="unbelievable" [2]="ublievable")
declare -a RETURNED_ARRAY2=([0]="1" [1]="3" [2]="4")
declare -a RETURNED_ARRAY3=([0]="0" [1]="0" [2]="0")
→ array::fuzzyFilter SC2 lines
declare -a LAST_RETURNED_ARRAY=([0]="self mock2")
declare -a LAST_RETURNED_ARRAY2=([0]="0")
declare -a LAST_RETURNED_ARRAY3=([0]="1")
declare -a RETURNED_ARRAY=([0]="self mock2")
declare -a RETURNED_ARRAY2=([0]="0")
declare -a RETURNED_ARRAY3=([0]="1")
→ array::fuzzyFilter u lines
declare -a LAST_RETURNED_ARRAY=([0]="very unbelievable" [1]="unbelievable" [2]="ublievable")
declare -a LAST_RETURNED_ARRAY2=([0]="5" [1]="0" [2]="0")
declare -a LAST_RETURNED_ARRAY3=([0]="5" [1]="0" [2]="0")
declare -a RETURNED_ARRAY=([0]="very unbelievable" [1]="unbelievable" [2]="ublievable")
declare -a RETURNED_ARRAY2=([0]="5" [1]="0" [2]="0")
declare -a RETURNED_ARRAY3=([0]="5" [1]="0" [2]="0")
→ array::fuzzyFilter seLf lines
declare -a LAST_RETURNED_ARRAY=([0]="self mock1" [1]="self mock2")
declare -a LAST_RETURNED_ARRAY2=([0]="0" [1]="0")
declare -a LAST_RETURNED_ARRAY3=([0]="0" [1]="0")
declare -a RETURNED_ARRAY=([0]="self mock1" [1]="self mock2")
declare -a RETURNED_ARRAY2=([0]="0" [1]="0")
declare -a RETURNED_ARRAY3=([0]="0" [1]="0")
→ array::fuzzyFilter nomatch lines
declare -a LAST_RETURNED_ARRAY=()
declare -a LAST_RETURNED_ARRAY2=()
declare -a LAST_RETURNED_ARRAY3=()
declare -a RETURNED_ARRAY=()
declare -a RETURNED_ARRAY2=()
declare -a RETURNED_ARRAY3=()
```

14 changes: 7 additions & 7 deletions tests.d/1001-main-functions/01.sort-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function testSortCommandsAndLastChoice() {
# overriding core::getLocalStateDirectory to return a temporary directory
setTempFilesNumber 700
io::createTempDirectory && local localStateDirectory="${LAST_RETURNED_VALUE}"
io::createTempDirectory && local localStateDirectory="${RETURNED_VALUE}"
VALET_CONFIG_LOCAL_STATE_DIRECTORY="${localStateDirectory}"
VALET_CONFIG_REMEMBER_LAST_CHOICES=5

Expand All @@ -15,7 +15,7 @@ another3 This is another command 3"

# testing commands sort and that without prior choices, the order of commands is kept
echo "→ main::sortCommands myid1 \"\${commands}\""
main::sortCommands "myid1" "${commands}" && echo "${LAST_RETURNED_VALUE}"
main::sortCommands "myid1" "${commands}" && echo "${RETURNED_VALUE}"
endTest "Testing main::sortCommands without prior choices, the order of commands is kept" $?

# testing commands sort after choosing another3 then cm2
Expand All @@ -24,26 +24,26 @@ another3 This is another command 3"
echo "→ main::sortCommands myid1 \"\${commands}\""
main::addLastChoice "myid1" "another3"
main::addLastChoice "myid1" "cm2"
main::sortCommands "myid1" "${commands}" && echo "${LAST_RETURNED_VALUE}"
main::sortCommands "myid1" "${commands}" && echo "${RETURNED_VALUE}"
endTest "Testing main::sortCommands after choosing another3 then cm2" $?

# testing with VALET_CONFIG_REMEMBER_LAST_CHOICES=0
echo "→ VALET_CONFIG_REMEMBER_LAST_CHOICES=0 main::sortCommands myid1 \"\${commands}\""
VALET_CONFIG_REMEMBER_LAST_CHOICES=0 main::sortCommands "myid1" "${commands}" && echo "${LAST_RETURNED_VALUE}"
VALET_CONFIG_REMEMBER_LAST_CHOICES=0 main::sortCommands "myid1" "${commands}" && echo "${RETURNED_VALUE}"
endTest "Testing main::sortCommands, with VALET_CONFIG_REMEMBER_LAST_CHOICES=0 the order does not change" $?
VALET_CONFIG_REMEMBER_LAST_CHOICES=5

# testing commands sort for another id, the order of commands should be the initial one
echo "→ main::sortCommands myid2 \"\${commands}\""
main::sortCommands "myid2" "${commands}" && echo "${LAST_RETURNED_VALUE}"
main::sortCommands "myid2" "${commands}" && echo "${RETURNED_VALUE}"
endTest "Testing main::sortCommands for another id, the order of commands should be the initial one" $?

# testing that after adding more than x commands, we only keep the last x
local -i i
for i in {1..10}; do
main::addLastChoice "myid1" "cm${i}"
done
io::readFile "${localStateDirectory}/last-choices-myid1" && local content="${LAST_RETURNED_VALUE}"
io::readFile "${localStateDirectory}/last-choices-myid1" && local content="${RETURNED_VALUE}"
echo "Content of last-choices-myid1:"
echo "${content}"
endTest "Testing main::addLastChoice after adding more than ${VALET_CONFIG_REMEMBER_LAST_CHOICES} commands, we only keep the last ${VALET_CONFIG_REMEMBER_LAST_CHOICES}" 0
Expand All @@ -52,7 +52,7 @@ another3 This is another command 3"
main::addLastChoice "myid1" "another3"
main::addLastChoice "myid1" "another3"
main::addLastChoice "myid1" "another3"
io::readFile "${localStateDirectory}/last-choices-myid1" && content="${LAST_RETURNED_VALUE}"
io::readFile "${localStateDirectory}/last-choices-myid1" && content="${RETURNED_VALUE}"
echo "Content of last-choices-myid1:"
echo "${content}"
endTest "Testing main::addLastChoice after adding the same command multiple times only keeps the last one" 0
Expand Down
14 changes: 7 additions & 7 deletions tests.d/1001-main-functions/02.arguments-parser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
function testMain::parseFunctionArguments() {

echo "→ main::parseFunctionArguments selfMock2"
main::parseFunctionArguments selfMock2 && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 more1 more2"
main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 more1 more2 && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 more1 more2 && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1"
main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 -o -2 optionValue2 arg1 && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 -unknown -what optionValue2 arg"
main::parseFunctionArguments selfMock2 -unknown -what optionValue2 arg && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 -unknown -what optionValue2 arg && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 arg more1 more2 -o"
main::parseFunctionArguments selfMock2 arg more1 more2 -o && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 arg more1 more2 -o && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 -this arg more1"
main::parseFunctionArguments selfMock2 -this arg more1 && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 -this arg more1 && echo "${RETURNED_VALUE}"
echo

echo "→ main::parseFunctionArguments selfMock2 --this-is-option2 --option1 arg more1"
main::parseFunctionArguments selfMock2 --this-is-option2 --option1 arg more1 && echo "${LAST_RETURNED_VALUE}"
main::parseFunctionArguments selfMock2 --this-is-option2 --option1 arg more1 && echo "${RETURNED_VALUE}"

endTest "Testing main::parseFunctionArguments" 0
}
Expand Down
28 changes: 14 additions & 14 deletions tests.d/1001-main-functions/99.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function testGetFunctionNameFromCommand() {
echo "→ main::getFunctionNameFromCommand 'self build'"
main::getFunctionNameFromCommand "self build" && echo "${LAST_RETURNED_VALUE}"
main::getFunctionNameFromCommand "self build" && echo "${RETURNED_VALUE}"

endTest "Testing main::getFunctionNameFromCommand" $?
}
Expand All @@ -11,52 +11,52 @@ function testFuzzyMatchCommandtoFunctionName() {

echo "→ main::fuzzyMatchCommandtoFunctionName 'se bu other stuff dont care'"
main::fuzzyMatchCommandtoFunctionName "se bu other stuff dont care"
echo "${LAST_RETURNED_VALUE}"
echo "${LAST_RETURNED_VALUE2}"
echo "${LAST_RETURNED_VALUE3}"
echo "${RETURNED_VALUE}"
echo "${RETURNED_VALUE2}"
echo "${RETURNED_VALUE3}"

echo
echo "→ main::fuzzyMatchCommandtoFunctionName 'sf' 'nop' 'other' 'stuff' 'dont care'"
main::fuzzyMatchCommandtoFunctionName "sf" "nop" "other" "stuff" "dont care"
echo "${LAST_RETURNED_VALUE}"
echo "${LAST_RETURNED_VALUE2}"
echo "${LAST_RETURNED_VALUE3}"
echo "${RETURNED_VALUE}"
echo "${RETURNED_VALUE2}"
echo "${RETURNED_VALUE3}"

endTest "Testing main::fuzzyMatchCommandtoFunctionName" 0
}

function testGetMaxPossibleCommandLevel() {

echo "→ main::getMaxPossibleCommandLevel '1' '2' '3'"
main::getMaxPossibleCommandLevel "1" "2" "3" && echo "${LAST_RETURNED_VALUE}"
main::getMaxPossibleCommandLevel "1" "2" "3" && echo "${RETURNED_VALUE}"

echo
echo "→ main::getMaxPossibleCommandLevel '1 2 3'"
main::getMaxPossibleCommandLevel "1 2 3" && echo "${LAST_RETURNED_VALUE}"
main::getMaxPossibleCommandLevel "1 2 3" && echo "${RETURNED_VALUE}"

echo
echo "→ main::getMaxPossibleCommandLevel '1'"
main::getMaxPossibleCommandLevel "1" && echo "${LAST_RETURNED_VALUE}"
main::getMaxPossibleCommandLevel "1" && echo "${RETURNED_VALUE}"

echo
echo "→ main::getMaxPossibleCommandLevel"
main::getMaxPossibleCommandLevel && echo "${LAST_RETURNED_VALUE}"
main::getMaxPossibleCommandLevel && echo "${RETURNED_VALUE}"

endTest "Testing main::getMaxPossibleCommandLevel" 0
}

function testFuzzyFindOption() {

echo "→ main::fuzzyFindOption '--opt1 --derp2 --allo3' 'de'"
main::fuzzyFindOption de --opt1 --derp2 --allo3 && echo "${LAST_RETURNED_VALUE}"
main::fuzzyFindOption de --opt1 --derp2 --allo3 && echo "${RETURNED_VALUE}"

echo
echo "→ main::fuzzyFindOption '--opt1 --derp2 --allo3' '-a'"
main::fuzzyFindOption -a --opt1 --derp2 --allo3 && echo "${LAST_RETURNED_VALUE}"
main::fuzzyFindOption -a --opt1 --derp2 --allo3 && echo "${RETURNED_VALUE}"

echo
echo "→ main::fuzzyFindOption '--opt1 --derp2 --allo3' 'thing'"
main::fuzzyFindOption thing --opt1 --derp2 --allo3 && echo "${LAST_RETURNED_VALUE}"
main::fuzzyFindOption thing --opt1 --derp2 --allo3 && echo "${RETURNED_VALUE}"

endTest "Testing main::fuzzyFindOption" 0
}
Expand Down
10 changes: 5 additions & 5 deletions tests.d/1002-lib-kurl/00.kurl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ function echoOutputKurlToFile() {

local debugMessage
debugMessage="kurl::toFile false function ended with exit code ⌈${exitCode}⌉."$'\n'
debugMessage+="http return code was ⌈${LAST_RETURNED_VALUE2}"$'\n'
debugMessage+="http return code was ⌈${RETURNED_VALUE2}"$'\n'
if [[ -s "${filePath}" ]]; then
debugMessage+="Content of downloaded file:"$'\n'"$(<"${filePath}")"$'\n'
fi
debugMessage+="stderr:"$'\n'"${LAST_RETURNED_VALUE}"
debugMessage+="stderr:"$'\n'"${RETURNED_VALUE}"
echo "${debugMessage}"
}

Expand Down Expand Up @@ -93,9 +93,9 @@ function echoOutputKurlToVar() {

local debugMessage
debugMessage="kurl::toVar function ended with exit code ⌈${exitCode}⌉."$'\n'
debugMessage+="http return code was ⌈${LAST_RETURNED_VALUE3}"$'\n'
debugMessage+="stdout:"$'\n'"${LAST_RETURNED_VALUE}"$'\n'
debugMessage+="stderr:"$'\n'"${LAST_RETURNED_VALUE2}"
debugMessage+="http return code was ⌈${RETURNED_VALUE3}"$'\n'
debugMessage+="stdout:"$'\n'"${RETURNED_VALUE}"$'\n'
debugMessage+="stderr:"$'\n'"${RETURNED_VALUE2}"
echo "${debugMessage}"
}

Expand Down
Loading

0 comments on commit 0979268

Please sign in to comment.