๐Ÿ“‚ core

core::checkParseResults

A convenience function to check the parsing results and fails with an error message if there are parsing errors. Will also display the help if the help option is true.

This should be called from a command function for which you want to check the parsing results.

  • $1: display help as bool: the help option
  • $2: parsing errors as string: the parsing errors
  • $3: function name as string: (optional) the function name (defaults to the calling function)
core::checkParseResults "${help:-}" "${parsingErrors:-}"
core::checkParseResults "${help:-}" "${parsingErrors:-}" "myFunctionName"

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::getLocalStateDirectory

Returns the path to the valet locla state directory. The base directory relative to which user-specific state files should be stored. Creates it if missing.

Returns:

  • RETURNED_VALUE: the path to the valet local state directory
core::getLocalStateDirectory
local directory="${RETURNED_VALUE}"

core::getUserDirectory

Returns the path to the valet user directory. Does not create it if missing.

Returns:

  • RETURNED_VALUE: the path to the valet user directory
core::getUserDirectory
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}โŒ."

core::parseArguments

Parse the arguments and options of a function and return a string that can be evaluated to set the variables. This should be called from a command function for which you want to parse the arguments.

See the documentation for more details on the parser: https://jcaillon.github.io/valet/docs/new-commands/#-implement-your-command.

  • $@: arguments as any: the arguments to parse

Returns:

  • RETURNED_VALUE: a string that can be evaluated to set the parsed variables

Output example:

local arg1 option1
arg1="xxx"
option1="xxx"
core::parseArguments "$@" && eval "${RETURNED_VALUE}"

core::reloadUserCommands

Forcibly source again the user ‘commands’ file from the valet user directory.

core::reloadUserCommands

core::resetIncludedFiles

Allows to reset the included files. When calling the source function, it will source all the files again. This is useful when we want to reload the libraries.

core::resetIncludedFiles

core::showHelp

Show the help for the current function. This should be called directly from a command function for which you want to display the help text.

core::showHelp

core::sourceFunction

Source the file associated with a command function. This allows you to call a command function without having to source the file manually.

  • $1: function name as string: the function name
core::sourceFunction "functionName"

core::sourceUserCommands

Source the user ‘commands’ file from the valet user directory. If the file does not exist, we build it on the fly.

core::sourceUserCommands

source

Allows to include a library file or sources a file.

It replaces the builtin source command to make sure that we do not include the same file twice. We replace source instead of creating a new function to allow us to specify the included file for spellcheck.

  • $1: library name 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 included file (mimics the builtin source command).
  source string array system
  source ./my/path my/other/path
  • The file can be relative to the current script (script that calls this function).
  • This function makes sure that we do not include the same file twice.
  • Use builtin source if you want to include the file even if it was already included.

Documentation generated for the version 0.26.6 (2024-11-24).