๐ core
core::createNewStateFilePath
Returns the path to a new file stored in the user state directory. Can be used to save the state of important temporary files generated during a program execution.
- $1: file suffix as string: The suffix for the file to create.
Returns:
- ${RETURNED_VALUE}: The path to the created file.
core::createNewStateFilePath "my-file"
printf '%s\n' "The file is โ${RETURNED_VALUE}โ."
core::dump
Dumps information about the current environment into a new state file.
- ${_OPTION_DUMP_SUFFIX} as string: (optional) The suffix for the file to create. (defaults to an empty string)
Returns:
- ${RETURNED_VALUE}: the path to the created file.
core::dump
core::fail
Displays an error message and then exit the program with error.
- $@: message as string: the error message to display
core::fail "This is an error message."
core::failWithCode
Displays an error message and then exit the program with error.
- $1: exit code as int: the exit code to use, should be between 1 and 255
- $@: message as string: the error message to display
core::failWithCode 255 "This is an error message."
core::getConfigurationDirectory
Returns the path to the valet configuration directory. Creates it if missing.
Returns:
- ${RETURNED_VALUE}: the path to the valet configuration directory
core::getConfigurationDirectory
local directory="${RETURNED_VALUE}"
core::getExtensionsDirectory
Returns the path to the user extensions directory. Does not create it if missing.
Returns:
- ${RETURNED_VALUE}: the path to the valet user directory
core::getExtensionsDirectory
local directory="${RETURNED_VALUE}"
core::getUserCacheDirectory
Returns the path to the valet local cache directory. Where user-specific non-essential (cached) data should be written (analogous to /var/cache). Creates it if missing.
Returns:
- ${RETURNED_VALUE}: the path to the valet local state directory
core::getUserCacheDirectory
local directory="${RETURNED_VALUE}"
core::getUserDataDirectory
Returns the path to the valet local data directory. Where user-specific data files should be written (analogous to /usr/share). Creates it if missing.
Returns:
- ${RETURNED_VALUE}: the path to the valet local state directory
core::getUserDataDirectory
local directory="${RETURNED_VALUE}"
core::getUserStateDirectory
Returns the path to the valet local cache directory. Where user-specific state files should be written (analogous to /var/lib). Ideal location for storing runtime information, logs, etc… Creates it if missing.
Returns:
- ${RETURNED_VALUE}: the path to the valet local state directory
core::getUserStateDirectory
local directory="${RETURNED_VALUE}"
core::getVersion
Returns the version of Valet.
Returns:
- ${RETURNED_VALUE}: The version of Valet.
core::getVersion
printf '%s\n' "The version of Valet is โ${RETURNED_VALUE}โ."
include
Allows to include multiple library files.
It calls source
for each argument.
Useful if you don’t have arguments to pass to the sourced files.
- $@: libraries as string: The names of the libraries (array, interactive, string…) or the file paths to include.
include string array ./my/path
source
Allows to source/include a library file or sources a file.
It replaces the builtin source command to make sure that we do not source the same library twice. We replace source instead of creating a new function to allow us to specify the included file for spellcheck.
- $1: library name or path as string: the name of the library (array, interactive, string…) or the file path to include.
- $@: arguments as any: (optional) the arguments to pass to the sourced file (mimics the builtin source command).
source string
source ./my/path
- The file can be relative to the current script (script that calls this function).
- Use
builtin source
if you want to include the file even if it was already included.