Skip to content

Commit

Permalink
✨ better defaults for logging options
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Apr 11, 2024
1 parent e36238b commit 9bda31c
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 254 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ jobs:
run: |
chmod +x valet
chmod +x valet.d/commands.d/self-build.sh
export VALET_CONFIG_DISABLE_COLORS=false
export VALET_CONFIG_DISABLE_NERDFONT_ICONS=true
export VALET_CONFIG_ENABLE_COLORS=true
./valet self test -C
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Auto parsing of arguments and options based on your command configuration:
![demo-parsing](docs/content/showcase/demo-parsing.gif)

> [!NOTE]
> This showcase is recorded with the [windows terminal][windows-terminal], [debian on WSL][debian-wsl] with zsh & [oh my zsh][oh-my-zsh]. The color scheme for the terminal is [dracula][dracula-theme] and the font is a homemade modification of windows Consolas (with ligatures + with nerd font icons).
> This showcase is recorded with the [windows terminal][windows-terminal], [debian on WSL][debian-wsl] with zsh & [oh my zsh][oh-my-zsh]. The color scheme for the terminal is [dracula][dracula-theme] and the font is a homemade modification of windows Consolas (with ligatures + with [nerd font icons][nerd-font]).
## 🎉 Installation

Expand Down Expand Up @@ -126,11 +126,6 @@ bash -c "$(curl -fsSL https://raw.githubusercontent.com/jcaillon/valet/main/vale

## 💻 Usage

> [!IMPORTANT]
> If you see the replacement character � in my terminal, it means you don't have a [nerd font][nerd-font] setup in your terminal.
>
> Either install a nerd font and activate it on our terminal or `export VALET_CONFIG_DISABLE_NERDFONT_ICONS=true` in your environment. This is reminded to you during the automated installation process.
### Adding your own commands

Valet is pre-configured with some example commands so you can try it immediately and see how it feels.
Expand Down Expand Up @@ -165,7 +160,6 @@ Please check the [CONTRIBUTING.md][contributing] documentation if you intend to

## 🔭 Roadmap

- reverse icons and colors settings, disabled by default.
- rename CMD_ variables.
- Document everything. Document test.
- Add full support for interactive mode.
Expand All @@ -181,12 +175,14 @@ Please check the [CONTRIBUTING.md][contributing] documentation if you intend to
- Allow to regroup single letter options (e.g. -fsSL).
- Add a command self package that build the user commands into a single script file.
- Add vscode extensions [recommendations](https://github.com/imfing/hextra-starter-template/blob/main/.vscode/extensions.json).
- fix running tests with verbose mode on.
- try to make interactive functions usable in colorless mode.
- for yes/no, add param to choose the default option.

[releases]: https://github.com/jcaillon/valet/releases
[latest-release]: https://github.com/jcaillon/valet/releases/latest
[new-command]: docs/create-new-command.md
[install-script]: ./valet.d/commands.d/self-install.sh
[examples]: ./examples.d
[license]: ./LICENSE
[contributing]: CONTRIBUTING.md
[bash]: https://www.gnu.org/software/bash/
Expand Down
49 changes: 49 additions & 0 deletions tests.d/1002-lib-kurl/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ stderr:
```

**Error** output:

```log
DEBUG Executing the command ⌜curl⌝.
Fail if it fails: ⌜false⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜false⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--silent --show-error --location --write-out %{http_code} --output /tmp/valet-work --code 200 http://hello.com⌝
DEBUG The command ⌜curl⌝ originally ended with exit code ⌜0⌝.
The error code ⌜0⌝ is acceptable and has been reset to 0.
Standard output:
⌜200⌝
Error output:
⌜▶ called curl --silent --show-error --location --write-out %{http_code} --output /tmp/valet-work --code 200 http://hello.com
DEBUG The curl command for url ⌜http://hello.com⌝ ended with exit code ⌜0⌝, the http return code was ⌜200⌝.
DEBUG The http return code ⌜200⌝ is acceptable and exit code has been reset to 0 from ⌜0⌝.
```

### Testing kurl, with no content http code 500, fails

Exit code: `1`
Expand All @@ -181,10 +201,39 @@ Exit code: `1`
**Error** output:

```log
DEBUG Executing the command ⌜curl⌝.
Fail if it fails: ⌜false⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜false⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--silent --show-error --location --write-out %{http_code} --output /tmp/valet-work --code 500 http://hello.com⌝
DEBUG The command ⌜curl⌝ originally ended with exit code ⌜0⌝.
The error code ⌜0⌝ is acceptable and has been reset to 0.
Standard output:
⌜500⌝
Error output:
⌜▶ called curl --silent --show-error --location --write-out %{http_code} --output /tmp/valet-work --code 500 http://hello.com
DEBUG The curl command for url ⌜http://hello.com⌝ ended with exit code ⌜0⌝, the http return code was ⌜500⌝.
ERROR The http return code ⌜500⌝ is not acceptable for url ⌜http://hello.com⌝.
Error output:
⌜▶ called curl --silent --show-error --location --write-out %{http_code} --output /tmp/valet-work --code 500 http://hello.com
stack:
├─ In function core::fail() $GLOBAL_VALET_HOME/valet.d/core:296
├─ In function kurl::toFile() $GLOBAL_VALET_HOME/valet.d/lib-kurl:55
├─ In function kurl::toVar() $GLOBAL_VALET_HOME/valet.d/lib-kurl:92
├─ In function testKurl::toVar() $GLOBAL_VALET_HOME/tests.d/1002-lib-kurl/00.kurl.sh:73
├─ In function main() $GLOBAL_VALET_HOME/tests.d/1002-lib-kurl/00.kurl.sh:101
├─ In function source() $GLOBAL_VALET_HOME/tests.d/1002-lib-kurl/00.kurl.sh:131
├─ In function source() $GLOBAL_VALET_HOME/valet.d/core:451
├─ In function runTest() valet.d/commands.d/self-test-utils:241
├─ In function runTestSuites() valet.d/commands.d/self-test-utils:195
├─ In function runCoreTests() valet.d/commands.d/self-test-utils:107
├─ In function selfTest() valet.d/commands.d/self-test.sh:110
├─ In function main::runFunction() $GLOBAL_VALET_HOME/valet.d/main:585
├─ In function main::parseMainArguments() $GLOBAL_VALET_HOME/valet.d/main:537
└─ In function main() ./valet:99
```

### Testing kurl, debug mode, with content http code 400
Expand Down
85 changes: 85 additions & 0 deletions tests.d/1005-lib-io/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ stderr from file:
```

**Error** output:

```log
DEBUG Executing the command ⌜fakeexec2⌝.
Fail if it fails: ⌜false⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--option argument1 argument2⌝
DEBUG The command ⌜fakeexec2⌝ originally ended with exit code ⌜0⌝.
The error code ⌜0⌝ is acceptable and has been reset to 0.
Standard output:
⌜▶ called fakeexec2 --option argument1 argument2
▶ fakeexec2 input stream was:
⌈⌉
Error output:
⌜This is an error output from fakeexec2
```

### Testing io::invoke3var, output to var

Exit code: `0`
Expand All @@ -270,6 +291,27 @@ stderr from var:
```

**Error** output:

```log
DEBUG Executing the command ⌜fakeexec2⌝.
Fail if it fails: ⌜false⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--option argument1 argument2⌝
DEBUG The command ⌜fakeexec2⌝ originally ended with exit code ⌜0⌝.
The error code ⌜0⌝ is acceptable and has been reset to 0.
Standard output:
⌜▶ called fakeexec2 --option argument1 argument2
▶ fakeexec2 input stream was:
⌈⌉
Error output:
⌜This is an error output from fakeexec2
```

### Testing io::invoke, should fail

Exit code: `1`
Expand All @@ -283,6 +325,12 @@ Exit code: `1`
**Error** output:

```log
DEBUG Executing the command ⌜fakeexec2⌝.
Fail if it fails: ⌜true⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--error⌝
ERROR The command ⌜fakeexec2⌝ originally ended with exit code ⌜1⌝.
Standard output:
⌜▶ called fakeexec2 --error
Expand All @@ -293,6 +341,22 @@ Error output:
⌜This is an error output from fakeexec2
returning 1 from fakeexec2
stack:
├─ In function core::fail() $GLOBAL_VALET_HOME/valet.d/core:296
├─ In function io::invoke5() $GLOBAL_VALET_HOME/valet.d/lib-io:120
├─ In function io::invoke5var() $GLOBAL_VALET_HOME/valet.d/lib-io:178
├─ In function io::invoke() $GLOBAL_VALET_HOME/valet.d/lib-io:226
├─ In function testIo::invoke() $GLOBAL_VALET_HOME/tests.d/1005-lib-io/01.invoke.sh:61
├─ In function main() $GLOBAL_VALET_HOME/tests.d/1005-lib-io/01.invoke.sh:115
├─ In function source() $GLOBAL_VALET_HOME/tests.d/1005-lib-io/01.invoke.sh:120
├─ In function source() $GLOBAL_VALET_HOME/valet.d/core:451
├─ In function runTest() valet.d/commands.d/self-test-utils:241
├─ In function runTestSuites() valet.d/commands.d/self-test-utils:195
├─ In function runCoreTests() valet.d/commands.d/self-test-utils:107
├─ In function selfTest() valet.d/commands.d/self-test.sh:110
├─ In function main::runFunction() $GLOBAL_VALET_HOME/valet.d/main:585
├─ In function main::parseMainArguments() $GLOBAL_VALET_HOME/valet.d/main:537
└─ In function main() ./valet:99
```

### Testing io::invoke, output to var
Expand All @@ -315,3 +379,24 @@ stderr from var:
```

**Error** output:

```log
DEBUG Executing the command ⌜fakeexec2⌝.
Fail if it fails: ⌜true⌝
Acceptable error codes: ⌜0⌝
Standard stream from file: ⌜⌝
Standard stream: ⌜⌝
Extra parameters: ⌜--option argument1 argument2⌝
DEBUG The command ⌜fakeexec2⌝ originally ended with exit code ⌜0⌝.
The error code ⌜0⌝ is acceptable and has been reset to 0.
Standard output:
⌜▶ called fakeexec2 --option argument1 argument2
▶ fakeexec2 input stream was:
⌈⌉
Error output:
⌜This is an error output from fakeexec2
```

6 changes: 3 additions & 3 deletions tests.d/1007-lib-interactive/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo y | interactive::promptYesNo 'Do you see this message?'
 ┌──┐
 │ Do you see this message? │
 └──┘\
[?25l[1m[7mCAB (Y)ES [0m [1m[7mCUB (N)O [0m[1G[0K[?25h[2m ┌─[4b─┐[0m
[?25l[1m[7m (Y)ES [0m [1m[7m (N)O [0m[1G[0K[?25h[2m ┌─[4b─┐[0m
 │ Yes. │
/└──┘
```
Expand All @@ -30,7 +30,7 @@ echo n | interactive::promptYesNo 'Do you see this message?'
 ┌──┐
 │ Do you see this message? │
 └──┘\
[?25l[1m[7mCAB (Y)ES [0m [1m[7mCUB (N)O [0m[1G[0K[?25h[2m ┌─[3b─┐[0m
[?25l[1m[7m (Y)ES [0m [1m[7m (N)O [0m[1G[0K[?25h[2m ┌─[3b─┐[0m
 │ No. │
/└──┘
```
Expand All @@ -46,7 +46,7 @@ echo y | interactive::askForConfirmation 'Please press OK.'
 ┌──┐
 │ Please press OK. │
 └──┘\
[?25l[1m[7mCAB (O)K [0m[1G[0K[?25h[2m ┌─[3b─┐[0m
[?25l[1m[7m (O)K [0m[1G[0K[?25h[2m ┌─[3b─┐[0m
 │ Ok. │
/└──┘
```
Expand Down
2 changes: 1 addition & 1 deletion tests.d/1100-self-config/01.self-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function testSelfConfig() {
export VALET_CONFIG_FILE="${configFile}"
export VALET_CONFIG_COLOR_DEBUG=$'\e[44m'
export VALET_CONFIG_LOG_COLUMNS=20
export VALET_CONFIG_ENABLE_CI_MODE=true
export VALET_CONFIG_ENABLE_LOG_TIMESTAMP=true
selfConfig --override --export-current-values
) && exitCode=0 || exitCode=$?
echo
Expand Down
44 changes: 24 additions & 20 deletions tests.d/1100-self-config/results.approved.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ cat ${configFile}
# Empty variables will be replaced by the default values during the execution.
# You should not define all the variables, only the ones you want to change.
# If you break this file, valet will fail to start.
# You can delete it and run the 'valet self config' command to recreate it.
# -----------
# General config
# -----------
Expand Down Expand Up @@ -65,24 +68,23 @@ VALET_CONFIG_REMEMBER_LAST_CHOICES="${VALET_CONFIG_REMEMBER_LAST_CHOICES:-}"
# -----------
# Log/output configuration
# -----------
# If true, will simplify the log output for CI/CD environments:
# will display the logs without colors, without icons, without wrapping lines and with the full date.
VALET_CONFIG_ENABLE_CI_MODE="${VALET_CONFIG_ENABLE_CI_MODE:-}"
# If true, will disable the icons (using nerd font).
VALET_CONFIG_DISABLE_NERDFONT_ICONS="${VALET_CONFIG_DISABLE_NERDFONT_ICONS:-}"
# If true, will enable the icons (using nerd font).
VALET_CONFIG_ENABLE_NERDFONT_ICONS="${VALET_CONFIG_ENABLE_NERDFONT_ICONS:-}"
# If true, will disable the color output (colors are still needed for interactive mode).
VALET_CONFIG_DISABLE_COLORS="${VALET_CONFIG_DISABLE_COLORS:-}"
# If true, will forcibly enable the color output (otherwise we try to detect color support on start).
VALET_CONFIG_ENABLE_COLORS="${VALET_CONFIG_ENABLE_COLORS:-}"
# If true, will disable the text wrapping for logs.
VALET_CONFIG_DISABLE_LOG_WRAP="${VALET_CONFIG_DISABLE_LOG_WRAP:-}"
# Sets the maximum width for the log output (used only when log wrapping is enabled).
VALET_CONFIG_LOG_COLUMNS="${VALET_CONFIG_LOG_COLUMNS:-}"
# If true, will disable the timestamp for logs.
VALET_CONFIG_DISABLE_LOG_TIMESTAMP="${VALET_CONFIG_DISABLE_LOG_TIMESTAMP:-}"
# If true, will disable the time for logs.
VALET_CONFIG_DISABLE_LOG_TIME="${VALET_CONFIG_DISABLE_LOG_TIME:-}"
# If true, will print a timestamp instead of simple time in the logs.
VALET_CONFIG_ENABLE_LOG_TIMESTAMP="${VALET_CONFIG_ENABLE_LOG_TIMESTAMP:-}"
# -----------
# Log icons configuration
Expand Down Expand Up @@ -212,6 +214,9 @@ cat ${configFile}
# Empty variables will be replaced by the default values during the execution.
# You should not define all the variables, only the ones you want to change.
# If you break this file, valet will fail to start.
# You can delete it and run the 'valet self config' command to recreate it.
# -----------
# General config
# -----------
Expand Down Expand Up @@ -253,24 +258,23 @@ VALET_CONFIG_REMEMBER_LAST_CHOICES="${VALET_CONFIG_REMEMBER_LAST_CHOICES:-}"
# -----------
# Log/output configuration
# -----------
# If true, will simplify the log output for CI/CD environments:
# will display the logs without colors, without icons, without wrapping lines and with the full date.
VALET_CONFIG_ENABLE_CI_MODE="${VALET_CONFIG_ENABLE_CI_MODE:-true}"
# If true, will disable the icons (using nerd font).
VALET_CONFIG_DISABLE_NERDFONT_ICONS="${VALET_CONFIG_DISABLE_NERDFONT_ICONS:-}"
# If true, will enable the icons (using nerd font).
VALET_CONFIG_ENABLE_NERDFONT_ICONS="${VALET_CONFIG_ENABLE_NERDFONT_ICONS:-}"
# If true, will disable the color output (colors are still needed for interactive mode).
VALET_CONFIG_DISABLE_COLORS="${VALET_CONFIG_DISABLE_COLORS:-}"
# If true, will forcibly enable the color output (otherwise we try to detect color support on start).
VALET_CONFIG_ENABLE_COLORS="${VALET_CONFIG_ENABLE_COLORS:-}"
# If true, will disable the text wrapping for logs.
VALET_CONFIG_DISABLE_LOG_WRAP="${VALET_CONFIG_DISABLE_LOG_WRAP:-}"
# Sets the maximum width for the log output (used only when log wrapping is enabled).
VALET_CONFIG_LOG_COLUMNS="${VALET_CONFIG_LOG_COLUMNS:-20}"
# If true, will disable the timestamp for logs.
VALET_CONFIG_DISABLE_LOG_TIMESTAMP="${VALET_CONFIG_DISABLE_LOG_TIMESTAMP:-}"
# If true, will disable the time for logs.
VALET_CONFIG_DISABLE_LOG_TIME="${VALET_CONFIG_DISABLE_LOG_TIME:-}"
# If true, will print a timestamp instead of simple time in the logs.
VALET_CONFIG_ENABLE_LOG_TIMESTAMP="${VALET_CONFIG_ENABLE_LOG_TIMESTAMP:-true}"
# -----------
# Log icons configuration
Expand Down
Loading

0 comments on commit 9bda31c

Please sign in to comment.