Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion examples/colors-usage/src/lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
if [[ "${NO_COLOR:-}" == "" ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
Expand All @@ -26,17 +37,26 @@ yellow() { print_in_color "\e[33m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
magenta() { print_in_color "\e[35m" "$*"; }
cyan() { print_in_color "\e[36m" "$*"; }
black() { print_in_color "\e[30m" "$*"; }
white() { print_in_color "\e[37m" "$*"; }

bold() { print_in_color "\e[1m" "$*"; }
underlined() { print_in_color "\e[4m" "$*"; }

red_bold() { print_in_color "\e[1;31m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
blue_bold() { print_in_color "\e[1;34m" "$*"; }
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
black_bold() { print_in_color "\e[1;30m" "$*"; }
white_bold() { print_in_color "\e[1;37m" "$*"; }

red_underlined() { print_in_color "\e[4;31m" "$*"; }
green_underlined() { print_in_color "\e[4;32m" "$*"; }
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }
black_underlined() { print_in_color "\e[4;30m" "$*"; }
white_underlined() { print_in_color "\e[4;37m" "$*"; }
10 changes: 10 additions & 0 deletions examples/dependencies-alt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ commands:
### `$ ./cli download`

````shell
# This file is located at 'src/download_command.sh'.
# It contains the implementation for the 'cli download' command.
# The code you write here will be wrapped by a function named 'cli_download_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args: none

deps:
- ${deps[git]} = /usr/bin/git
- ${deps[http_client]} = /usr/bin/curl
- ${deps[ruby]} = /home/vagrant/.rbenv/versions/3.4.1/bin/ruby


````
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ISSUE TRACKER
AUTHORS
Lana Lang.

Version 0.1.0 April 2025 download(1)
Version 0.1.0 May 2025 download(1)


````
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.2
.\"
.TH "download" "1" "May 2025" "Version 0.1.0" "Sample application"
.TH "download" "1" "June 2025" "Version 0.1.0" "Sample application"
.SH NAME
\f[B]download\f[R] \- Sample application
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% May 2025
% June 2025

NAME
==================================================
Expand Down
40 changes: 32 additions & 8 deletions examples/validations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ commands:
validate: file_exists

- name: build
help: Build the project
environment_variables:
- name: build_dir
help: Path to the build directory
default: release

# Validations also work on environment variables
validate: dir_exists

- name: deploy
help: Deploy to production
flags:
- long: --user
help: Username
arg: username
required: true
validate: not_empty
````


Expand Down Expand Up @@ -116,17 +126,31 @@ must be an existing directory

````

### `$ BUILD_DIR=src ./validate build`
### `$ BUILD_DIR=src ./validate build\`

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

environment variables:
- $BUILD_DIR = src

````

### `$ ./validate deploy --user ''`

````shell
validation error in --user USERNAME:
must not be empty


````

### `$ ./validate deploy --user admin`

````shell
# This file is located at 'src/deploy_command.sh'.
# It contains the implementation for the 'validate deploy' command.
# The code you write here will be wrapped by a function named 'validate_deploy_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[--user]} = admin


````
Expand Down
10 changes: 10 additions & 0 deletions examples/validations/src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ commands:
validate: file_exists

- name: build
help: Build the project
environment_variables:
- name: build_dir
help: Path to the build directory
default: release

# Validations also work on environment variables
validate: dir_exists

- name: deploy
help: Deploy to production
flags:
- long: --user
help: Username
arg: username
required: true
validate: not_empty
5 changes: 5 additions & 0 deletions examples/validations/src/deploy_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo "# This file is located at 'src/deploy_command.sh'."
echo "# It contains the implementation for the 'validate deploy' command."
echo "# The code you write here will be wrapped by a function named 'validate_deploy_command()'."
echo "# Feel free to edit this file; your changes will persist when regenerating."
inspect_args
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_dir_exists() {
[[ -d "$1" ]] || echo "must be an existing directory"
if [[ ! -d "$1" ]]; then
echo "must be an existing directory"
fi
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_file_exists() {
[[ -f "$1" ]] || echo "must be an existing file"
if [[ ! -f "$1" ]]; then
echo "must be an existing file"
fi
}
6 changes: 4 additions & 2 deletions examples/validations/src/lib/validations/validate_integer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_integer() {
[[ "$1" =~ ^[0-9]+$ ]] || echo "must be an integer"
}
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "must be an integer"
fi
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_not_empty() {
[[ -z "$1" ]] && echo "must not be empty"
if [[ -z "$1" ]]; then
echo "must not be empty"
fi
}
5 changes: 4 additions & 1 deletion examples/validations/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ bashly generate
./validate calc 1 2 --save no-such-file.txt

./validate build
BUILD_DIR=src ./validate build
BUILD_DIR=src ./validate build\

./validate deploy --user ''
./validate deploy --user admin
4 changes: 3 additions & 1 deletion lib/bashly/libraries/validations/validate_dir_exists.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_dir_exists() {
[[ -d "$1" ]] || echo "must be an existing directory"
if [[ ! -d "$1" ]]; then
echo "must be an existing directory"
fi
}
4 changes: 3 additions & 1 deletion lib/bashly/libraries/validations/validate_file_exists.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_file_exists() {
[[ -f "$1" ]] || echo "must be an existing file"
if [[ ! -f "$1" ]]; then
echo "must be an existing file"
fi
}
6 changes: 4 additions & 2 deletions lib/bashly/libraries/validations/validate_integer.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_integer() {
[[ "$1" =~ ^[0-9]+$ ]] || echo "must be an integer"
}
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "must be an integer"
fi
}
4 changes: 3 additions & 1 deletion lib/bashly/libraries/validations/validate_not_empty.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_not_empty() {
[[ -z "$1" ]] && echo "must not be empty"
if [[ -z "$1" ]]; then
echo "must not be empty"
fi
}
2 changes: 1 addition & 1 deletion spec/approvals/examples/render-mandoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ ISSUE TRACKER
AUTHORS
Lana Lang.

Version 0.1.0 May 2025 download(1)
Version 0.1.0 June 2025 download(1)
11 changes: 11 additions & 0 deletions spec/approvals/examples/validations
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ created src/lib/validations/validate_not_empty.sh
creating user files in src
created src/calc_command.sh
created src/build_command.sh
created src/deploy_command.sh
created ./validate
run ./validate --help to test your bash script
+ ./validate calc 1 2 --save README.md
Expand Down Expand Up @@ -40,3 +41,13 @@ args: none

environment variables:
- $BUILD_DIR = src
+ ./validate deploy --user ''
validation error in --user USERNAME:
must not be empty
+ ./validate deploy --user admin
# This file is located at 'src/deploy_command.sh'.
# It contains the implementation for the 'validate deploy' command.
# The code you write here will be wrapped by a function named 'validate_deploy_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[--user]} = admin
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_file_exists() {
[[ -f "$1" ]] || echo "must be an existing file"
if [[ ! -f "$1" ]]; then
echo "must be an existing file"
fi
}
22 changes: 21 additions & 1 deletion spec/fixtures/workspaces/lib-upgrade/src/lib/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
## Color output will be disabled if `NO_COLOR` environment variable is set
## in compliance with https://no-color.org/
##
## In case you wish to enable auto detection for color output based on the
## terminal being interactive (TTY), call `enable_auto_colors` in your
## `src/initialize.sh` (Run `bashly add hooks` to add this file).
##
enable_auto_colors() {
## If NO_COLOR has not been set and stdout is not a TTY, disable colors
if [[ -z ${NO_COLOR+x} && ! -t 1 ]]; then
NO_COLOR=1
fi
}

print_in_color() {
local color="$1"
shift
if [[ -z ${NO_COLOR+x} ]]; then
if [[ "${NO_COLOR:-}" == "" ]]; then
printf "$color%b\e[0m\n" "$*"
else
printf "%b\n" "$*"
Expand All @@ -26,17 +37,26 @@ yellow() { print_in_color "\e[33m" "$*"; }
blue() { print_in_color "\e[34m" "$*"; }
magenta() { print_in_color "\e[35m" "$*"; }
cyan() { print_in_color "\e[36m" "$*"; }
black() { print_in_color "\e[30m" "$*"; }
white() { print_in_color "\e[37m" "$*"; }

bold() { print_in_color "\e[1m" "$*"; }
underlined() { print_in_color "\e[4m" "$*"; }

red_bold() { print_in_color "\e[1;31m" "$*"; }
green_bold() { print_in_color "\e[1;32m" "$*"; }
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
blue_bold() { print_in_color "\e[1;34m" "$*"; }
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
black_bold() { print_in_color "\e[1;30m" "$*"; }
white_bold() { print_in_color "\e[1;37m" "$*"; }

red_underlined() { print_in_color "\e[4;31m" "$*"; }
green_underlined() { print_in_color "\e[4;32m" "$*"; }
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }
black_underlined() { print_in_color "\e[4;30m" "$*"; }
white_underlined() { print_in_color "\e[4;37m" "$*"; }
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_dir_exists() {
[[ -d "$1" ]] || echo "must be an existing directory"
if [[ ! -d "$1" ]]; then
echo "must be an existing directory"
fi
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_file_exists() {
[[ -f "$1" ]] || echo "must be an existing file"
if [[ ! -f "$1" ]]; then
echo "must be an existing file"
fi
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_integer() {
[[ "$1" =~ ^[0-9]+$ ]] || echo "must be an integer"
}
if ! [[ "$1" =~ ^[0-9]+$ ]]; then
echo "must be an integer"
fi
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## [@bashly-upgrade validations]
validate_not_empty() {
[[ -z "$1" ]] && echo "must not be empty"
if [[ -z "$1" ]]; then
echo "must not be empty"
fi
}