Skip to content

Commit

Permalink
♻️ finishing huge refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Jan 29, 2025
1 parent ebf7f64 commit ad58c9c
Show file tree
Hide file tree
Showing 57 changed files with 1,668 additions and 2,607 deletions.
2 changes: 1 addition & 1 deletion commands.d/self-add-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function selfAddCommand() {
fi

local fileName="${commandName// /-}"
string::kebabCaseToCamelCase "${fileName}"
string::convertKebabCaseToCamelCase "${fileName}"
local functionName="${RETURNED_VALUE}"
local newCommandFilePath="${PWD}/commands.d/${fileName}.sh"
local commandTemplateFile="${GLOBAL_INSTALLATION_DIRECTORY}/extras/template-command-${templateFlavor}.sh"
Expand Down
8 changes: 4 additions & 4 deletions commands.d/self-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function declareFinalCommandDefinitionHelpVariables() {
optionValue="${TEMP_CMD_BUILD_options_name[index]}"
if [[ ${optionValue} == *"<"* ]]; then optionValue="<${optionValue##*<}"; else optionValue="true"; fi
selfBuild_extractFirstLongNameFromOptionString "${TEMP_CMD_BUILD_options_name[index]}"
string::kebabCaseToSnakeCase "${RETURNED_VALUE}"
string::convertKebabCaseToSnakeCase "${RETURNED_VALUE}"
TEMP_CMD_BUILD_options_description[index]+=$'\n'"This option can be set by exporting the variable VALET_${RETURNED_VALUE}='${optionValue}'."
fi
done
Expand Down Expand Up @@ -509,9 +509,9 @@ function declareFinalCommandDefinitionParserVariables() {
option="${option//,/ }"
string::trimAll "${option}" && option="${RETURNED_VALUE}"
selfBuild_extractFirstLongNameFromOptionString "${option}" && optionName="${RETURNED_VALUE}"
string::kebabCaseToCamelCase "${optionName}" && optionNameCc="${RETURNED_VALUE}"
string::convertKebabCaseToCamelCase "${optionName}" && optionNameCc="${RETURNED_VALUE}"
if [[ "${optionNoEnvVar}" != "true" ]]; then
string::kebabCaseToSnakeCase "${optionName}" && optionNameSc="VALET_${RETURNED_VALUE}"
string::convertKebabCaseToSnakeCase "${optionName}" && optionNameSc="VALET_${RETURNED_VALUE}"
else
optionNameSc=""
fi
Expand All @@ -537,7 +537,7 @@ function declareFinalCommandDefinitionParserVariables() {
argument="${argument//\?/}"
nbOptionalArguments+=1
fi
string::kebabCaseToCamelCase "${argument}" && argumentNameCc="${RETURNED_VALUE}"
string::convertKebabCaseToCamelCase "${argument}" && argumentNameCc="${RETURNED_VALUE}"

eval "CMD_ARGS_NAME_${function}+=(\"${argumentNameCc}\")"
done
Expand Down
4 changes: 3 additions & 1 deletion commands.d/self-document.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ source system
source array
# shellcheck source=../libraries.d/lib-fs
source fs
# shellcheck source=../libraries.d/lib-time
source time

#===============================================================
# >>> command: self document
Expand Down Expand Up @@ -94,7 +96,7 @@ function selfDocument::getFooter() {
core::getVersion
local version="${RETURNED_VALUE}"

system::date "%(%F)T"
time::getDate "%(%F)T"
local currentDate="${RETURNED_VALUE}"
RETURNED_VALUE="Documentation generated for the version ${version} (${currentDate})."
}
Expand Down
12 changes: 7 additions & 5 deletions commands.d/self-extend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ source interactive
source progress
# shellcheck source=../libraries.d/lib-curl
source curl
# shellcheck source=../libraries.d/lib-bash
source bash

#===============================================================
# >>> command: self extend
Expand Down Expand Up @@ -144,7 +146,7 @@ function selfExtend() {
# if Git is not installed, we download the source tarball and extract it
# We will only be able to do that for a few git servers however
log::info "Git is not installed, we will attempt to download the source tarball for the extension ⌜${extensionName}⌝."
if system::getNotExistingCommands curl tar; then
if bash::getMissingCommands curl tar; then
local IFS=$'\n'
core::fail "The following tools are required for this command but are not installed:"$'\n'"${RETURNED_ARRAY[*]}"
fi
Expand Down Expand Up @@ -217,7 +219,7 @@ function selfExtend_createExtension() {
selfDocument
fi

system::os
system::getOs
local os="${RETURNED_VALUE}"
if [[ ${os} == "windows" ]]; then
# shellcheck source=../libraries.d/lib-windows
Expand Down Expand Up @@ -303,7 +305,7 @@ function selfExtend_downloadTarball() {
# download the tarball
log::info "Downloading the extension from the URL ⌜${tarballUrl}⌝ for sha1 ⌜${sha1}⌝."
progress::start "#spinner Download in progress, please wait..."
curl::toFile true 200,302 "${tempDirectory}/${sha1}.tar.gz" "${tarballUrl}"
curl::download true 200,302 "${tempDirectory}/${sha1}.tar.gz" "${tarballUrl}"
progress::stop

# untar
Expand Down Expand Up @@ -348,9 +350,9 @@ function selfExtend_getSha1() {
RETURNED_VALUE=""
progress::start "#spinner Fetching reference information from GitHub..."
local url="https://api.github.com/repos/${owner}/${repo}/git/refs/heads/${reference}"
if ! curl::toVar false '200' -H "Accept: application/vnd.github.v3+json" "${url}"; then
if ! curl::request false '200' -H "Accept: application/vnd.github.v3+json" "${url}"; then
url="https://api.github.com/repos/${owner}/${repo}/git/refs/tags/${reference}"
curl::toVar false '200' -H "Accept: application/vnd.github.v3+json" "${url}" || :
curl::request false '200' -H "Accept: application/vnd.github.v3+json" "${url}" || :
fi
local response="${RETURNED_VALUE}"
local error="${RETURNED_VALUE2}"
Expand Down
4 changes: 2 additions & 2 deletions commands.d/self-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function selfUpdate() {
fi

# get the os
system::os
system::getOs
local os="${RETURNED_VALUE}"
log::debug "The current OS is ⌜${os}⌝."

Expand Down Expand Up @@ -724,7 +724,7 @@ if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
" "${EPOCHSECONDS}" "ERROR" "$*"
exit 1
}
function system::os() {
function system::getOs() {
case "${OSTYPE:-}" in
darwin*) RETURNED_VALUE="darwin" ;;
linux*) RETURNED_VALUE="linux" ;;
Expand Down
10 changes: 6 additions & 4 deletions commands.d/self-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ source version
source exe
# shellcheck source=../libraries.d/lib-fs
source fs
# shellcheck source=../libraries.d/lib-regex
source regex

#===============================================================
# >>> self release valet
Expand Down Expand Up @@ -79,7 +81,7 @@ function selfRelease() {

# get the latest release
local latestReleaseVersion
curl::toVar true '200' -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/jcaillon/valet/releases/latest"
curl::request true '200' -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/jcaillon/valet/releases/latest"
lastReleaseJson="${RETURNED_VALUE}"
if [[ ${lastReleaseJson} =~ "tag_name\":"([ ]?)"\"v"([^\"]+)"\"" ]]; then
latestReleaseVersion="v${BASH_REMATCH[2]}"
Expand Down Expand Up @@ -245,7 +247,7 @@ function selfRelease::createRelease() {
local uploadUrl
local createdReleaseJson
if [[ "${dryRun:-}" != "true" ]]; then
curl::toVar true '201,422' -X POST \
curl::request true '201,422' -X POST \
-H "Authorization: token ${githubReleaseToken:-}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-type: application/json; charset=utf-8" \
Expand Down Expand Up @@ -286,7 +288,7 @@ function selfRelease::uploadArtifact() {
# upload the artifact
if [[ "${dryRun:-}" != "true" && -n "${uploadUrl}" ]]; then
log::info "Uploading the artifact ⌜${artifactPath}⌝ to ⌜${uploadUrl}⌝."
curl::toVar true '' -X POST \
curl::request true '' -X POST \
-H "Authorization: token ${githubReleaseToken:-}" \
-H "Content-Type: application/tar+gzip" \
--data-binary "@${artifactPath}" \
Expand Down Expand Up @@ -400,7 +402,7 @@ function selfRelease::writeAllFunctionsDocumentation() {
local key
for key in "${SORTED_FUNCTION_NAMES[@]}"; do
local functionName="${key}"
string::regexGetFirst "${functionName}" '([[:alnum:]]+)::'
regex::getFirstGroup "${functionName}" '([[:alnum:]]+)::'
local packageName="${RETURNED_VALUE}"
if [[ -z "${packageName}" ]]; then
# case for "source" function
Expand Down
8 changes: 5 additions & 3 deletions commands.d/self-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ source progress
source bash
# shellcheck source=../libraries.d/lib-fs
source fs
# shellcheck source=../libraries.d/lib-time
source time

#===============================================================
# >>> command: self test
Expand Down Expand Up @@ -82,7 +84,7 @@ function selfTest() {
command::parseArguments "$@" && eval "${RETURNED_VALUE}"
command::checkParsedResults

core::getProgramElapsedMicroseconds
time::getProgramElapsedMicroseconds
local startTimeInMicroSeconds="${RETURNED_VALUE}"

# check what will be used to display the diff between received and approved files
Expand Down Expand Up @@ -161,8 +163,8 @@ function selfTest() {
fi
fi

core::getProgramElapsedMicroseconds
string::microsecondsToHuman $((RETURNED_VALUE - startTimeInMicroSeconds)) "%S seconds and %l ms"
time::getProgramElapsedMicroseconds
time::convertMicrosecondsToHuman $((RETURNED_VALUE - startTimeInMicroSeconds)) "%S seconds and %l ms"
log::info "Total time running tests: ⌜${RETURNED_VALUE}⌝."

if ((${#_TEST_FAILED_TEST_SUITES[@]} > 0)); then
Expand Down
29 changes: 20 additions & 9 deletions docs/content/docs/300.libraries/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ The bash built-in `source` is overridden by a function in Valet. This allows to

## 🎀 Available core libraries

<!-- https://v1.heroicons.com/ -->
For more details, please check the documentation on each library:

{{< cards >}}
{{< card link="ansi-codes" icon="code" title="ansi-code" subtitle="This library exports variables containing ASCII escape codes, enabling interactive programs." >}}
{{< card link="array" icon="clipboard-list" title="array" subtitle="Functions to manipulate bash arrays." >}}
{{< card link="benchmark" icon="trending-up" title="benchmark" subtitle="Functions to benchmark bash functions." >}}
{{< card link="ansi-codes" icon="annotation" title="ansi-code" subtitle="Declares variables containing ASCII escape codes, enabling interactive programs." >}}
{{< card link="array" icon="table" title="array" subtitle="Manipulate bash arrays." >}}
{{< card link="bash" icon="code" title="bash" subtitle="Extend bash capabilities." >}}
{{< card link="benchmark" icon="trending-up" title="benchmark" subtitle="Benchmark bash functions." >}}
{{< card link="command" icon="ticket" title="command" subtitle="Functions to be used in your commands." >}}
{{< card link="core" icon="star" title="core" subtitle="The core functions of Valet." >}}
{{< card link="fsfs" icon="table" title="fsfs" subtitle="Functions to display a full screen fuzzy search, which is used for the Valet menus." >}}
{{< card link="interactive" icon="cursor-click" title="interactive" subtitle="Functions to make your program interactive." >}}
{{< card link="io" icon="lightning-bolt" title="io" subtitle="Functions for file manipulation, command execution..." >}}
{{< card link="curl" icon="cloud-download" title="curl" subtitle="Wrapper functions around curl." >}}
{{< card link="exe" icon="star" title="exe" subtitle="Run commands and executables." >}}
{{< card link="fs" icon="document" title="fs" subtitle="Manipulate the files and directories." >}}
{{< card link="http" icon="cloud-download" title="http" subtitle="Naive http implementation." >}}
{{< card link="interactive" icon="cursor-click" title="interactive" subtitle="Make your command interactive." >}}
{{< card link="log" icon="pencil-alt" title="log" subtitle="Logging functions." >}}
{{< card link="profiler" icon="finger-print" title="profiler" subtitle="Functions enable and disable the bash profiler." >}}
{{< card link="string" icon="menu-alt-2" title="string" subtitle="Functions for string manipulation." >}}
{{< card link="profiler" icon="finger-print" title="profiler" subtitle="Enable and disable the bash profiler." >}}
{{< card link="progress" icon="dots-horizontal" title="progress" subtitle="Display a progress bar or a spinner." >}}
{{< card link="prompt" icon="chevron-right" title="prompt" subtitle="Prompt the user for input." >}}
{{< card link="regex" icon="tag" title="regex" subtitle="Use regular expressions." >}}
{{< card link="sfzf" icon="template" title="sfzf" subtitle="Simple fuzzy search interface, similar to fzf." >}}
{{< card link="string" icon="scissors" title="string" subtitle="Functions for string manipulation." >}}
{{< card link="system" icon="desktop-computer" title="system" subtitle="Functions to get system/user information." >}}
{{< card link="test" icon="badge-check" title="test" subtitle="Functions usable in your test scripts." >}}
{{< card link="time" icon="clock" title="time" subtitle="Functions related to time." >}}
{{< card link="tui" icon="terminal" title="tui" subtitle="Built terminal UI apps with these helper functions." >}}
{{< card link="version" icon="calculator" title="version" subtitle="Compare and manipulate semantic versions." >}}
{{< card link="windows" icon="view-grid" title="windows" subtitle="Functions specific to windows systems." >}}
{{< /cards >}}
8 changes: 4 additions & 4 deletions docs/content/docs/300.libraries/curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cascade:
url: /docs/libraries/curl
---

## curl::toFile
## curl::download

This function is a wrapper around curl.
It allows you to check the http status code and return 1 if it is not acceptable.
Expand All @@ -30,11 +30,11 @@ Returns:
- `RETURNED_VALUE2`: the http status code

```bash
curl::toFile "true" "200,201" "/filePath" "https://example.com" || core::fail "The curl command failed."
curl::download "true" "200,201" "/filePath" "https://example.com" || core::fail "The curl command failed."
```


## curl::toVar
## curl::request

This function is a wrapper around curl.
It allows you to check the http status code and return 1 if it is not acceptable.
Expand All @@ -58,7 +58,7 @@ Returns:
- `RETURNED_VALUE3`: the http status code

```bash
curl::toVar false 200,201 https://example.com || core::fail "The curl command failed."
curl::request false 200,201 https://example.com || core::fail "The curl command failed."
```


Expand Down
16 changes: 8 additions & 8 deletions docs/content/docs/300.libraries/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ windows::convertPathFromUnix "/path/to/file"
> Handles paths starting with `/mnt/x/` or `/x/`.

## exe::countArgs
## bash::countArgs

Returns the number of arguments passed.

A convenient function that can be used to:

- count the files/directories in a directory
`exe::countArgs "${PWD}"/* && local numberOfFiles="${RETURNED_VALUE}"`
`bash::countArgs "${PWD}"/* && local numberOfFiles="${RETURNED_VALUE}"`
- count the number of variables starting with VALET_
`exe::countArgs "${!VALET_@}" && local numberOfVariables="${RETURNED_VALUE}"`
`bash::countArgs "${!VALET_@}" && local numberOfVariables="${RETURNED_VALUE}"`

- $@: **arguments** _as any_:
the arguments to count
Expand All @@ -114,7 +114,7 @@ Returns:
- `RETURNED_VALUE`: The number of arguments passed.

```bash
exe::countArgs 1 2 3
bash::countArgs 1 2 3
```


Expand Down Expand Up @@ -556,7 +556,7 @@ fs::readFile "/path/to/file" 500 && local fileContent="${RETURNED_VALUE}"
```


## exe::readStdIn
## bash::readStdIn

Read the content of the standard input.
Will immediately return if the standard input is empty.
Expand All @@ -566,11 +566,11 @@ Returns:
- `RETURNED_VALUE`: The content of the standard input.

```bash
exe::readStdIn && local stdIn="${RETURNED_VALUE}"
bash::readStdIn && local stdIn="${RETURNED_VALUE}"
```


## exe::sleep
## bash::sleep

Sleep for the given amount of time.
This is a pure bash replacement of sleep.
Expand All @@ -579,7 +579,7 @@ This is a pure bash replacement of sleep.
the time to sleep in seconds (can be a float)

```bash
io:sleep 1.5
bash::sleep 1.5
```

> The sleep command is not a built-in command in bash, but a separate executable. When you use sleep, you are creating a new process.
Expand Down
Loading

0 comments on commit ad58c9c

Please sign in to comment.