diff --git a/README.md b/README.md index f24012d..4d67095 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ Please check the [CONTRIBUTING.md][contributing] documentation if you intend to - Betters checks in self build! - Support alternative single comments `# ## VALET COMMAND` instead of multiline comments for command declaration (see we can have help in autocompletion). - A command can declare dependencies to auto check if some tools are installed before running the command. +- Generate vscode snippets from each function in core and lib-* to provide autocompletion for users. [releases]: https://github.com/jcaillon/valet/releases [latest-release]: https://github.com/jcaillon/valet/releases/latest diff --git a/docs/content/_index.md b/docs/content/_index.md index 79d21ea..d478e72 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -23,6 +23,8 @@ keywords: {{< /hextra/hero-headline >}} +Valet is a zero dependency framework that helps you build fast, robust, testable and interactive bash scripts. +
{{< hextra/hero-subtitle >}} Build awesome bash scripts! diff --git a/tests.d/1001-main-functions/01.sort-commands.sh b/tests.d/1001-main-functions/01.sort-commands.sh index 80a2f59..ec832b9 100644 --- a/tests.d/1001-main-functions/01.sort-commands.sh +++ b/tests.d/1001-main-functions/01.sort-commands.sh @@ -2,7 +2,6 @@ function testSortCommandsAndLastChoice() { # overriding core::getLocalStateDirectory to return a temporary directory - setTempFilesNumber 700 io::createTempDirectory && local localStateDirectory="${RETURNED_VALUE}" VALET_CONFIG_LOCAL_STATE_DIRECTORY="${localStateDirectory}" VALET_CONFIG_REMEMBER_LAST_CHOICES=5 diff --git a/tests.d/1005-lib-io/01.invoke.sh b/tests.d/1005-lib-io/01.invoke.sh index ea8615b..3afcd4e 100644 --- a/tests.d/1005-lib-io/01.invoke.sh +++ b/tests.d/1005-lib-io/01.invoke.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash function testIo::invoke5() { - setTempFilesNumber 300 io::createTempFile && local tmpFile="${RETURNED_VALUE}" local -i exitCode diff --git a/tests.d/1100-self-config/01.self-config.sh b/tests.d/1100-self-config/01.self-config.sh index 1ee317e..579120f 100644 --- a/tests.d/1100-self-config/01.self-config.sh +++ b/tests.d/1100-self-config/01.self-config.sh @@ -8,7 +8,6 @@ function testSelfConfig() { local -i exitCode local originalConfigFile="${VALET_CONFIG_FILE:-}" local configFile - setTempFilesNumber 400 io::createTempFile && configFile="${RETURNED_VALUE}" VALET_CONFIG_FILE="${configFile}" diff --git a/tests.d/1100-self-config/results.approved.md b/tests.d/1100-self-config/results.approved.md index b6d9457..7acef4f 100644 --- a/tests.d/1100-self-config/results.approved.md +++ b/tests.d/1100-self-config/results.approved.md @@ -10,7 +10,7 @@ Exit code: `0` ```plaintext → selfConfig -▶ called myEditor: /tmp/valet.d/f401-0 +▶ called myEditor: /tmp/valet.d/f1-0 cat ${configFile} #!/usr/bin/env bash @@ -200,8 +200,8 @@ VALET_CONFIG_BUMP_VERSION_ON_BUILD="${VALET_CONFIG_BUMP_VERSION_ON_BUILD:-}" **Error** output: ```log -INFO Creating the valet config file ⌜/tmp/valet.d/f401-0⌝. -INFO Opening the valet config file ⌜/tmp/valet.d/f401-0⌝. +INFO Creating the valet config file ⌜/tmp/valet.d/f1-0⌝. +INFO Opening the valet config file ⌜/tmp/valet.d/f1-0⌝. ``` ### Testing selfConfig (should only open, file exists) @@ -212,13 +212,13 @@ Exit code: `0` ```plaintext → selfConfig -▶ called myEditor: /tmp/valet.d/f401-0 +▶ called myEditor: /tmp/valet.d/f1-0 ``` **Error** output: ```log -INFO Opening the valet config file ⌜/tmp/valet.d/f401-0⌝. +INFO Opening the valet config file ⌜/tmp/valet.d/f1-0⌝. ``` ### Testing selfConfig override no edit @@ -234,7 +234,7 @@ Exit code: `0` **Error** output: ```log -INFO Creating the valet config file ⌜/tmp/valet.d/f401-0⌝. +INFO Creating the valet config file ⌜/tmp/valet.d/f1-0⌝. ``` ### Testing selfConfig override export @@ -245,7 +245,7 @@ Exit code: `0` ```plaintext → (selfConfig --override --export-current-values) -▶ called myEditor: /tmp/valet.d/f401-0 +▶ called myEditor: /tmp/valet.d/f1-0 cat ${configFile} #!/usr/bin/env bash @@ -435,7 +435,7 @@ VALET_CONFIG_BUMP_VERSION_ON_BUILD="${VALET_CONFIG_BUMP_VERSION_ON_BUILD:-}" **Error** output: ```log -INFO Creating the valet config file ⌜/tmp/valet.d/f401-0⌝. -INFO Opening the valet config file ⌜/tmp/valet.d/f401-0⌝. +INFO Creating the valet config file ⌜/tmp/valet.d/f1-0⌝. +INFO Opening the valet config file ⌜/tmp/valet.d/f1-0⌝. ``` diff --git a/tests.d/1102-self-build/01.self-build.sh b/tests.d/1102-self-build/01.self-build.sh index 7ab6d15..2af9750 100644 --- a/tests.d/1102-self-build/01.self-build.sh +++ b/tests.d/1102-self-build/01.self-build.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash function testSelfBuild() { - setTempFilesNumber 500 io::createTempFile && local tempFile="${RETURNED_VALUE}" ( diff --git a/tests.d/1102-self-build/results.approved.md b/tests.d/1102-self-build/results.approved.md index 7ce098e..3d3dac5 100644 --- a/tests.d/1102-self-build/results.approved.md +++ b/tests.d/1102-self-build/results.approved.md @@ -230,7 +230,7 @@ self mock3 A command that only for testing valet core functions. self release Release a new version of valet. self setup The command run after the installation of Valet to setup the tool. -INFO The command definition variables have been written to ⌜/tmp/valet.d/f501-0⌝. +INFO The command definition variables have been written to ⌜/tmp/valet.d/f1-0⌝. SUCCESS The valet user commands have been successfully built ``` diff --git a/tests.d/1103-self-release/01.self-release.sh b/tests.d/1103-self-release/01.self-release.sh index 5c73788..1408a18 100644 --- a/tests.d/1103-self-release/01.self-release.sh +++ b/tests.d/1103-self-release/01.self-release.sh @@ -65,7 +65,6 @@ function kurl::toFile() { } function main() { - setTempFilesNumber 100 io::createTempFile && local tmpFile="${RETURNED_VALUE}" cp -f "${GLOBAL_VALET_HOME}/valet.d/version" "${tmpFile}" echo -n "1.2.3" > "${GLOBAL_VALET_HOME}/valet.d/version" diff --git a/tests.d/1104-self-setup/00.self-setup.sh b/tests.d/1104-self-setup/00.self-setup.sh index 6e5929c..05a6461 100644 --- a/tests.d/1104-self-setup/00.self-setup.sh +++ b/tests.d/1104-self-setup/00.self-setup.sh @@ -6,7 +6,6 @@ function testselfSetup() { local -i exitCode local originalConfigFile="${VALET_CONFIG_FILE:-}" local configFile - setTempFilesNumber 800 io::createTempFile && configFile="${RETURNED_VALUE}" VALET_CONFIG_FILE="${configFile}" diff --git a/tests.d/1104-self-setup/results.approved.md b/tests.d/1104-self-setup/results.approved.md index 262316d..52d4bbf 100644 --- a/tests.d/1104-self-setup/results.approved.md +++ b/tests.d/1104-self-setup/results.approved.md @@ -52,7 +52,7 @@ INFO If you see the replacement character ? in my terminal, it means you don You can download any font here: https://www.nerdfonts.com/font-downloads and install it. After that, you need to setup your terminal to use this newly installed font. You can also choose to enable the icons in Valet if you plan to install a nerd font. -INFO Creating the valet config file ⌜/tmp/valet.d/f801-0⌝. +INFO Creating the valet config file ⌜/tmp/valet.d/f1-0⌝. SUCCESS You are all set! INFO As a reminder, you can modify the configuration done during this set up by either: - replaying the command ⌜valet self setup⌝, @@ -107,7 +107,7 @@ An information icon: II ```log INFO Now setting up Valet. -CININFO II CDE Creating the valet config file CHI⌜/tmp/valet.d/f801-0⌝CDE. +CININFO II CDE Creating the valet config file CHI⌜/tmp/valet.d/f1-0⌝CDE. CWAWARNING IW CDE The tool CHI⌜awk⌝CDE is missing. It is needed for cleaning the profiler logs. CWAWARNING IW CDE The tool CHI⌜diff⌝CDE is missing. It is needed for the self test command. CWAWARNING IW CDE The tool CHI⌜curl⌝CDE is missing. It is needed for the self update command. diff --git a/tests.d/1300-valet-cli/.before-test b/tests.d/1300-valet-cli/.before-test index 9fd1d4f..9b35e6d 100644 --- a/tests.d/1300-valet-cli/.before-test +++ b/tests.d/1300-valet-cli/.before-test @@ -24,7 +24,6 @@ fi _TEST_0000_COMMON_UTILS=1 # override the local state and config directories to return temp directories -setTempFilesNumber 800 io::createTempDirectory export TEST_VALET_CONFIG_LOCAL_STATE_DIRECTORY="${RETURNED_VALUE}" diff --git a/tests.d/1300-valet-cli/06.misc.sh b/tests.d/1300-valet-cli/06.misc.sh index 402d041..89723ca 100644 --- a/tests.d/1300-valet-cli/06.misc.sh +++ b/tests.d/1300-valet-cli/06.misc.sh @@ -30,7 +30,6 @@ function testCleaning() { function testUserDirectory() { # testing with a non exising user directory local previousUserDirectory="${VALET_USER_DIRECTORY:-}" - setTempFilesNumber 600 io::createTempDirectory && export VALET_USER_DIRECTORY="${RETURNED_VALUE}/non-existing" echo "→ VALET_USER_DIRECTORY=non-existing self mock1 logging-level" diff --git a/tests.d/1300-valet-cli/results.approved.md b/tests.d/1300-valet-cli/results.approved.md index b2116b7..044e6ac 100644 --- a/tests.d/1300-valet-cli/results.approved.md +++ b/tests.d/1300-valet-cli/results.approved.md @@ -744,9 +744,9 @@ Exit code: `1` **Error** output: ```log -INFO The valet user directory ⌜/tmp/valet.d/d601-0/non-existing⌝ does not contain a built ⌜commands⌝ file. +INFO The valet user directory ⌜/tmp/valet.d/d2-0/non-existing⌝ does not contain a built ⌜commands⌝ file. Now building it using ⌜valet self build⌝ command. -WARNING Skipping user directory ⌜/tmp/valet.d/d601-0/non-existing⌝ because it does not exist. +WARNING Skipping user directory ⌜/tmp/valet.d/d2-0/non-existing⌝ because it does not exist. TRACE This is an error trace message which is always displayed. INFO This is an info message with a super long sentence. The value of life is not in its duration, but in its donation. You are not important because of how long you live, you are important because of how effective you live. Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. Surround yourself with the best people you can find, delegate authority, and don't interfere as long as the policy you've decided upon is being carried out. SUCCESS This is a success message. diff --git a/tests.d/1301-profiler/00.profiler.sh b/tests.d/1301-profiler/00.profiler.sh index 425d839..3b3df1b 100644 --- a/tests.d/1301-profiler/00.profiler.sh +++ b/tests.d/1301-profiler/00.profiler.sh @@ -7,7 +7,6 @@ commentTest "The profiler is an excellent tool to debug your command. The follow function testProfiler() { # testing command profiling + startup - setTempFilesNumber 200 io::createTempFile && export VALET_CONFIG_COMMAND_PROFILING_FILE="${RETURNED_VALUE}" io::createTempFile && export VALET_CONFIG_STARTUP_PROFILING_FILE="${RETURNED_VALUE}" export VALET_CONFIG_COMMAND_PROFILING_FILE diff --git a/tests.d/1301-profiler/results.approved.md b/tests.d/1301-profiler/results.approved.md index ebcb7ad..1d3243e 100644 --- a/tests.d/1301-profiler/results.approved.md +++ b/tests.d/1301-profiler/results.approved.md @@ -49,7 +49,7 @@ D I S timer delta source:line function **Error** output: ```log -INFO Starting profiler, writing in ⌜/tmp/valet.d/f201-0⌝. main +INFO Starting profiler, writing in ⌜/tmp/valet.d/f1-0⌝. main INFO First argument: arg1. INFO Option 1: . INFO Option 2: . @@ -72,7 +72,7 @@ A command profiling file has been created to log everything happening in the cho **Error** output: ```log -INFO Starting profiler, writing in ⌜/tmp/valet.d/f202-0⌝. +INFO Starting profiler, writing in ⌜/tmp/valet.d/f2-0⌝. TRACE This is an error trace message which is always displayed. ``` diff --git a/valet.d/commands.d/self-test-utils b/valet.d/commands.d/self-test-utils index 69f99da..928785c 100644 --- a/valet.d/commands.d/self-test-utils +++ b/valet.d/commands.d/self-test-utils @@ -86,8 +86,7 @@ function endTest() { # Usage: # setTempFilesNumber 3 function setTempFilesNumber() { - TEMPORARY_FILE_NUMBER=${1} - TEMPORARY_DIRECTORY_NUMBER=${1} + return 0 } function echoFileWithLineNumberSubstitution() { @@ -121,7 +120,7 @@ function runCoreTests() { # we should always run the test suite from the valet home directory to have consistent paths # in the report files - pushd "${GLOBAL_VALET_HOME}" 1> /dev/null + pushd "${GLOBAL_VALET_HOME}" 1>/dev/null log::info "Running all test suites in directory ⌜${GLOBAL_VALET_HOME}/tests.d⌝." runTestSuites "${GLOBAL_VALET_HOME}/tests.d" @@ -137,7 +136,7 @@ function runCoreTests() { runTestSuites "${GLOBAL_VALET_HOME}/examples.d/showcase/tests.d" fi - popd 1> /dev/null + popd 1>/dev/null # reload the orignal commands core::reloadUserCommands @@ -148,7 +147,7 @@ function rebuildCommands() { log::getLevel && originalLogLevel="${RETURNED_VALUE}" log::setLevel warning true core::sourceFunction selfBuild - if (( $# == 1)); then + if (($# == 1)); then selfBuild --user-directory "${1:-}" else selfBuild --user-directory "${1:-}" --output "${2}" @@ -171,13 +170,10 @@ function rebuildCommands() { function runTestSuites() { local testSuiteDirectory="${1}" - # reset the temp files - io::cleanupTempFiles - - io::createTempFile && _TEST_STANDARD_OUTPUT_FILE="${RETURNED_VALUE}" - io::createTempFile && _TEST_STANDARD_ERROR_FILE="${RETURNED_VALUE}" - io::createTempFile && _TEST_REPORT_FILE="${RETURNED_VALUE}" - io::createTempFile && _TEST_TEMP_FILE="${RETURNED_VALUE}" + _TEST_STANDARD_OUTPUT_FILE="${GLOBAL_TEMPORARY_IN_MEM_PREFIX}${BASHPID}.valet-test-stdout" + _TEST_STANDARD_ERROR_FILE="${GLOBAL_TEMPORARY_IN_MEM_PREFIX}${BASHPID}.valet-test-stderr" + _TEST_REPORT_FILE="${GLOBAL_TEMPORARY_IN_MEM_PREFIX}${BASHPID}.valet-test-report" + _TEST_TEMP_FILE="${GLOBAL_TEMPORARY_IN_MEM_PREFIX}${BASHPID}.valet-test-tempfile" # save the original important variables so we can restore them after the test suite log::getLevel @@ -213,6 +209,9 @@ function runTestSuites() { continue fi + # reset the temp files + io::cleanupTempFiles + log::info "Running test suite ⌜${testDirectory##*/}⌝." # run a custom user script before the test suite if it exists diff --git a/valet.d/core b/valet.d/core index 9574ea4..157ca74 100644 --- a/valet.d/core +++ b/valet.d/core @@ -224,6 +224,7 @@ function log::printFileString() { return 0; } # Display a string in the log. # The string will be aligned with the current log output and hard wrapped if necessary. +# Does not check the log level. # # $1: the content to log (can contain new lines) # $2: the string with which to prepend each wrapped line (empty by default) @@ -234,6 +235,7 @@ function log::printFileString() { return 0; } function log::printString() { return 0; } # Display something in the log stream. +# Does not check the log level. # # $1: the content to print (can contain new lines) # @@ -333,13 +335,13 @@ function log::createPrintFunction() { printStatement=' printf "'"${printfFormat}"'" '"${printfArguments}"' 1>&'"${VALET_CONFIG_LOG_FD:-2}" standardPrintStatement=' - printf "%s" "${toPrint}" 1>&'"${VALET_CONFIG_LOG_FD:-2}" + printf "%s" "${toPrint:-}" 1>&'"${VALET_CONFIG_LOG_FD:-2}" else # it is a file printStatement=' printf "'"${printfFormat}"'" '"${printfArguments}"' 1>>'"${VALET_CONFIG_LOG_FD}" standardPrintStatement=' - printf "%s" "${toPrint}" 1>>'"${VALET_CONFIG_LOG_FD}" + printf "%s" "${toPrint:-}" 1>>'"${VALET_CONFIG_LOG_FD}" fi # string with the number of spaces necessary to align with other log messages diff --git a/valet.d/version b/valet.d/version index 0133dde..9f50519 100644 --- a/valet.d/version +++ b/valet.d/version @@ -1 +1 @@ -0.11.167 \ No newline at end of file +0.11.198 \ No newline at end of file