Skip to content

Commit aa462ec

Browse files
authored
Merge pull request #634 from DannyBen/fix/validate_not_empty
Fix premature exit in `validate_not_empty` validation function
2 parents 444eea2 + b96ba35 commit aa462ec

File tree

25 files changed

+160
-31
lines changed

25 files changed

+160
-31
lines changed

examples/colors-usage/src/lib/colors.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,21 @@
1010
## Color output will be disabled if `NO_COLOR` environment variable is set
1111
## in compliance with https://no-color.org/
1212
##
13+
## In case you wish to enable auto detection for color output based on the
14+
## terminal being interactive (TTY), call `enable_auto_colors` in your
15+
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
16+
##
17+
enable_auto_colors() {
18+
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
19+
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
20+
NO_COLOR=1
21+
fi
22+
}
23+
1324
print_in_color() {
1425
local color="$1"
1526
shift
16-
if [[ -z ${NO_COLOR+x} ]]; then
27+
if [[ "${NO_COLOR:-}" == "" ]]; then
1728
printf "$color%b\e[0m\n" "$*"
1829
else
1930
printf "%b\n" "$*"
@@ -26,17 +37,26 @@ yellow() { print_in_color "\e[33m" "$*"; }
2637
blue() { print_in_color "\e[34m" "$*"; }
2738
magenta() { print_in_color "\e[35m" "$*"; }
2839
cyan() { print_in_color "\e[36m" "$*"; }
40+
black() { print_in_color "\e[30m" "$*"; }
41+
white() { print_in_color "\e[37m" "$*"; }
42+
2943
bold() { print_in_color "\e[1m" "$*"; }
3044
underlined() { print_in_color "\e[4m" "$*"; }
45+
3146
red_bold() { print_in_color "\e[1;31m" "$*"; }
3247
green_bold() { print_in_color "\e[1;32m" "$*"; }
3348
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
3449
blue_bold() { print_in_color "\e[1;34m" "$*"; }
3550
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
3651
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
52+
black_bold() { print_in_color "\e[1;30m" "$*"; }
53+
white_bold() { print_in_color "\e[1;37m" "$*"; }
54+
3755
red_underlined() { print_in_color "\e[4;31m" "$*"; }
3856
green_underlined() { print_in_color "\e[4;32m" "$*"; }
3957
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
4058
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
4159
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
4260
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }
61+
black_underlined() { print_in_color "\e[4;30m" "$*"; }
62+
white_underlined() { print_in_color "\e[4;37m" "$*"; }

examples/dependencies-alt/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ commands:
5252
### `$ ./cli download`
5353

5454
````shell
55+
# This file is located at 'src/download_command.sh'.
56+
# It contains the implementation for the 'cli download' command.
57+
# The code you write here will be wrapped by a function named 'cli_download_command()'.
58+
# Feel free to edit this file; your changes will persist when regenerating.
59+
args: none
60+
61+
deps:
62+
- ${deps[git]} = /usr/bin/git
63+
- ${deps[http_client]} = /usr/bin/curl
64+
- ${deps[ruby]} = /home/vagrant/.rbenv/versions/3.4.1/bin/ruby
5565

5666

5767
````

examples/render-mandoc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ISSUE TRACKER
102102
AUTHORS
103103
Lana Lang.
104104

105-
Version 0.1.0 April 2025 download(1)
105+
Version 0.1.0 May 2025 download(1)
106106

107107

108108
````

examples/render-mandoc/docs/download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.2
22
.\"
3-
.TH "download" "1" "May 2025" "Version 0.1.0" "Sample application"
3+
.TH "download" "1" "June 2025" "Version 0.1.0" "Sample application"
44
.SH NAME
55
\f[B]download\f[R] \- Sample application
66
.SH SYNOPSIS

examples/render-mandoc/docs/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% download(1) Version 0.1.0 | Sample application
22
% Lana Lang
3-
% May 2025
3+
% June 2025
44

55
NAME
66
==================================================

examples/validations/README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,23 @@ commands:
5252
validate: file_exists
5353

5454
- name: build
55+
help: Build the project
5556
environment_variables:
5657
- name: build_dir
5758
help: Path to the build directory
5859
default: release
5960

6061
# Validations also work on environment variables
6162
validate: dir_exists
63+
64+
- name: deploy
65+
help: Deploy to production
66+
flags:
67+
- long: --user
68+
help: Username
69+
arg: username
70+
required: true
71+
validate: not_empty
6272
````
6373

6474

@@ -116,17 +126,31 @@ must be an existing directory
116126

117127
````
118128

119-
### `$ BUILD_DIR=src ./validate build`
129+
### `$ BUILD_DIR=src ./validate build\`
120130

121131
````shell
122-
# This file is located at 'src/build_command.sh'.
123-
# It contains the implementation for the 'validate build' command.
124-
# The code you write here will be wrapped by a function named 'validate_build_command()'.
125-
# Feel free to edit this file; your changes will persist when regenerating.
126-
args: none
127132

128-
environment variables:
129-
- $BUILD_DIR = src
133+
134+
````
135+
136+
### `$ ./validate deploy --user ''`
137+
138+
````shell
139+
validation error in --user USERNAME:
140+
must not be empty
141+
142+
143+
````
144+
145+
### `$ ./validate deploy --user admin`
146+
147+
````shell
148+
# This file is located at 'src/deploy_command.sh'.
149+
# It contains the implementation for the 'validate deploy' command.
150+
# The code you write here will be wrapped by a function named 'validate_deploy_command()'.
151+
# Feel free to edit this file; your changes will persist when regenerating.
152+
args:
153+
- ${args[--user]} = admin
130154

131155

132156
````

examples/validations/src/bashly.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ commands:
2828
validate: file_exists
2929

3030
- name: build
31+
help: Build the project
3132
environment_variables:
3233
- name: build_dir
3334
help: Path to the build directory
3435
default: release
3536

3637
# Validations also work on environment variables
3738
validate: dir_exists
39+
40+
- name: deploy
41+
help: Deploy to production
42+
flags:
43+
- long: --user
44+
help: Username
45+
arg: username
46+
required: true
47+
validate: not_empty
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
echo "# This file is located at 'src/deploy_command.sh'."
2+
echo "# It contains the implementation for the 'validate deploy' command."
3+
echo "# The code you write here will be wrapped by a function named 'validate_deploy_command()'."
4+
echo "# Feel free to edit this file; your changes will persist when regenerating."
5+
inspect_args
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## [@bashly-upgrade validations]
22
validate_dir_exists() {
3-
[[ -d "$1" ]] || echo "must be an existing directory"
3+
if [[ ! -d "$1" ]]; then
4+
echo "must be an existing directory"
5+
fi
46
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## [@bashly-upgrade validations]
22
validate_file_exists() {
3-
[[ -f "$1" ]] || echo "must be an existing file"
3+
if [[ ! -f "$1" ]]; then
4+
echo "must be an existing file"
5+
fi
46
}

0 commit comments

Comments
 (0)