Skip to content

Commit

Permalink
✨ added multiple functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Dec 4, 2024
1 parent cb81550 commit fd88856
Show file tree
Hide file tree
Showing 11 changed files with 504 additions and 67 deletions.
8 changes: 3 additions & 5 deletions docs/content/docs/800.roadmap/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ url: /docs/roadmap

This page lists the features that I would like to implement in Valet. They come in addition to new features described in the [issues][valet-issues].

- Add utility functions to install stuff from the extension.setup.sh scripts `powershell.exe -NoProfile -NonInteractive -Command "echo ok" 2>/dev/null`:
- system::addToPath
- system::addToPathIfNotPresent
- Finish prompt and interactive functions.
- Self-command to create a new command interactively.
- Add full support for interactive mode.
- Add HOW TO documentation:
- how to build and share a CLI application with Valet
- how to use valet from your bash prompt
- how to use valet in your existing scripts
- Finish prompt and interactive functions.
- Add full support for interactive mode.
- For dropdown with a set list of options, we can verify that the input value is one of the expected value.
- For argument and option autocompletion, accept any multiline string that will be eval and that should set RETURNED_ARRAY with the list of possible completion.
- Generate an autocompletion script for bash and zsh.
Expand All @@ -32,5 +29,6 @@ This page lists the features that I would like to implement in Valet. They come
- test if folder is writeable
- Implement regex replace in pure bash.
- Add `valet.cmd` to the package, in self setup we can optionally add the valet install dir to the windows PATH.
- Also export user defined functions.

[valet-issues]: https://github.com/jcaillon/valet/issues
32 changes: 21 additions & 11 deletions tests.d/1004-lib-system/00.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# shellcheck source=../../valet.d/lib-system
source system
# shellcheck source=../../valet.d/lib-io
source io

function testSystem::os() {

Expand Down Expand Up @@ -137,29 +139,26 @@ function test_system::addToPath() {
}

function test_system::windowsSetEnvVar() {
# shellcheck disable=SC2317
function powershell() { echo "powershell: $*"; }

echo "→ system::windowsSetEnvVar VAR VALUE"
OSTYPE=msys system::windowsSetEnvVar VAR VALUE
echo
echo "→ system::windowsSetEnvVar VAR ''"
OSTYPE=msys system::windowsSetEnvVar VAR ''
echo

unset -f powershell
test::endTest "Testing system::windowsSetEnvVar" 0
}

function test_system::windowsAddToPath() {
# shellcheck disable=SC2317
function powershell() { echo "powershell: $*"; }
function test_system::windowsGetEnvVar() {
echo "→ system::windowsGetEnvVar VAR"
OSTYPE=msys system::windowsGetEnvVar VAR
echo
test::endTest "Testing system::windowsGetEnvVar" 0
}

function test_system::windowsAddToPath() {
echo "→ system::windowsAddToPath /coucou"
OSTYPE=msys system::windowsAddToPath /coucou
echo

unset -f powershell
test::endTest "Testing system::windowsAddToPath" 0
}

Expand All @@ -172,7 +171,18 @@ function main() {
testSystem::commandExists
test_system::addToPath
test_system::windowsSetEnvVar
test_system::windowsGetEnvVar
test_system::windowsAddToPath
}

main
# backup original function
io::invoke declare -f io::runPs1Command
_ORIGINAL_FUNCTION="${RETURNED_VALUE//declare -? /}"

# shellcheck disable=SC2317
function io::runPs1Command() { echo "io::runPs1Command: $*"; }

main

unset -f io::runPs1Command
eval "${_ORIGINAL_FUNCTION}"
25 changes: 21 additions & 4 deletions tests.d/1004-lib-system/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,27 @@ Exit code: `0`

```plaintext
→ system::windowsSetEnvVar VAR VALUE
powershell: -NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop'; $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true); $key.SetValue('VAR', 'VALUE', 'ExpandString');; exit $LASTEXITCODE;
io::runPs1Command: $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true); $key.SetValue('VAR', 'VALUE', 'ExpandString');
→ system::windowsSetEnvVar VAR ''
powershell: -NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop'; $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true); $key.DeleteValue('VAR');; exit $LASTEXITCODE;
io::runPs1Command: $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true); $key.DeleteValue('VAR');
```

### Testing system::windowsGetEnvVar

Exit code: `0`

**Standard** output:

```plaintext
→ system::windowsGetEnvVar VAR
io::runPs1Command:
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true);
$value = $key.GetValue('VAR', '', 'DoNotExpandEnvironmentNames');
$key.Dispose();
Write-Output $value;
```

Expand All @@ -188,7 +205,7 @@ Exit code: `0`

```plaintext
→ system::windowsAddToPath /coucou
powershell: -NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop';
io::runPs1Command:
$pathToAdd = '\coucou';
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true);
$oldPath = $key.GetValue('Path', '', 'DoNotExpandEnvironmentNames').TrimEnd([IO.Path]::PathSeparator);
Expand All @@ -197,7 +214,7 @@ powershell: -NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop';
$key.SetValue('Path', $newPath, 'ExpandString');
};
$key.Dispose();
; exit $LASTEXITCODE;
```

Expand Down
29 changes: 13 additions & 16 deletions tests.d/1005-lib-io/00.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,6 @@ function testIo::isDirectoryWritable() {
test::endTest "Testing io::isDirectoryWritable" 0
}

function test_io::runPs1Command() {
function powershell() { echo "$*"; }

echo "→ io::runPs1Command 'Get-Process'"
io::runPs1Command 'Get-Process'
echo "$?"

echo "→ io::runPs1Command 'echo \\\"ok\\\"' true"
io::runPs1Command 'echo "ok"' true
echo "$?"

unset -f powershell
test::endTest "Testing io::runPs1Command" 0
}

function test_io::convertToWindowsPath() {
echo "→ io::convertToWindowsPath '/tmp/file'"
io::convertToWindowsPath '/tmp/file'
Expand All @@ -191,6 +176,18 @@ function test_io::convertToWindowsPath() {
test::endTest "Testing io::convertToWindowsPath" 0
}

function test_io::convertFromWindowsPath() {
printf "%s\n" "→ io::convertFromWindowsPath 'C:\\Users\\username'"
io::convertFromWindowsPath 'C:\Users\username'
echo "${RETURNED_VALUE}"

printf "%s\n" "→ io::convertFromWindowsPath 'D:\\data\\file'"
io::convertFromWindowsPath 'D:\data\file'
echo "${RETURNED_VALUE}"

test::endTest "Testing io::convertFromWindowsPath" 0
}

function test_io::createLink() {
function ln() { echo "ln: $*"; }
local osType="${OSTYPE:-}"
Expand Down Expand Up @@ -222,9 +219,9 @@ function main() {
testIo::readStdIn
testIo::countArgs
testIo::isDirectoryWritable
test_io::runPs1Command
test_io::convertToWindowsPath
test_io::createLink
test_io::convertFromWindowsPath
}

main
33 changes: 12 additions & 21 deletions tests.d/1005-lib-io/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,6 @@ Writable
Writable
```

### Testing io::runPs1Command

Exit code: `0`

**Standard** output:

```plaintext
→ io::runPs1Command 'Get-Process'
-NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop'; Get-Process; exit $LASTEXITCODE;
0
→ io::runPs1Command 'echo \"ok\"' true
-NoProfile -NonInteractive -Command $ErrorActionPreference = 'Stop'; $process = Start-Process powershell "-NoProfile -NonInteractive -Command `"$ErrorActionPreference = 'Stop'; echo `\`"ok`\`"; exit $LASTEXITCODE;`"" -PassThru -Wait -Verb RunAs; exit $process.ExitCode
0
```

### Testing io::convertToWindowsPath

Exit code: `0`
Expand All @@ -244,17 +229,23 @@ Exit code: `0`
```plaintext
→ io::createLink 'resources/gitignored/file' 'resources/gitignored/try/file2' true
ln: $GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/file $GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try/file2
Created hard link: ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/file⌝ ← ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try/file2⌝.
$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try
→ io::createLink 'resources/gitignored/try' 'resources/gitignored/new'
ln: -s $GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try $GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/new
Created symbolic link: ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try⌝ ← ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/new⌝.
$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored
```

**Error** output:
### Testing io::convertFromWindowsPath

```log
INFO Created hard link: ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/file⌝ ← ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try/file2⌝.
INFO Created symbolic link: ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/try⌝ ← ⌜$GLOBAL_VALET_HOME/tests.d/1005-lib-io/resources/gitignored/new⌝.
Exit code: `0`

**Standard** output:

```plaintext
→ io::convertFromWindowsPath 'C:\Users\username'
/c/Users/username
→ io::convertFromWindowsPath 'D:\data\file'
/d/data/file
```

## Test script 01.invoke
Expand Down
6 changes: 5 additions & 1 deletion tests.d/1103-self-release/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ DEBUG Found function: ⌜io::isDirectoryWritable⌝
DEBUG Found function: ⌜io::runPs1Command⌝
DEBUG Found function: ⌜io::createLink⌝
DEBUG Found function: ⌜io::convertToWindowsPath⌝
DEBUG Found function: ⌜io::convertFromWindowsPath⌝
DEBUG Found function: ⌜io::createWindowsTempFile⌝
DEBUG Found function: ⌜io::createWindowsTempDirectory⌝
DEBUG Found function: ⌜profiler::enable⌝
DEBUG Found function: ⌜profiler::disable⌝
DEBUG Found function: ⌜prompt::autocompletion⌝
Expand All @@ -221,10 +224,11 @@ DEBUG Found function: ⌜system::commandExists⌝
DEBUG Found function: ⌜system::isRoot⌝
DEBUG Found function: ⌜system::addToPath⌝
DEBUG Found function: ⌜system::windowsSetEnvVar⌝
DEBUG Found function: ⌜system::windowsGetEnvVar⌝
DEBUG Found function: ⌜system::windowsAddToPath⌝
DEBUG Found function: ⌜test::commentTest⌝
DEBUG Found function: ⌜test::endTest⌝
INFO Found 122 functions with documentation.
INFO Found 126 functions with documentation.
▶ called io::writeToFile $GLOBAL_VALET_HOME/extras/lib-valet.md
INFO The documentation has been generated in ⌜$GLOBAL_VALET_HOME/extras/lib-valet.md⌝.
▶ called io::writeToFile $GLOBAL_VALET_HOME/extras/lib-valet
Expand Down
Loading

0 comments on commit fd88856

Please sign in to comment.