File tree Expand file tree Collapse file tree 7 files changed +63
-3
lines changed
Expand file tree Collapse file tree 7 files changed +63
-3
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
6161- [ yaml] ( yaml#readme ) - using the YAML reading functions
6262- [ colors] ( colors#readme ) - using the color print feature
6363- [ completions] ( completions#readme ) - adding bash completion functionality
64- - [ validations] ( validations#readme ) - adding argument validation functions
64+ - [ validations] ( validations#readme ) - adding validation functions for arguments, flags or environment variables
6565- [ hooks] ( hooks#readme ) - adding before/after hooks
6666
6767## Real-world-like examples
Original file line number Diff line number Diff line change @@ -83,15 +83,15 @@ Options:
8383### ` $ ./cli --add deploy `
8484
8585```` shell
86- --add requires --command
86+ --add needs --command
8787
8888
8989````
9090
9191### ` $ ./cli --add deploy --command 'git push' `
9292
9393```` shell
94- --add requires --target
94+ --add needs --target
9595
9696
9797````
Original file line number Diff line number Diff line change @@ -50,6 +50,15 @@ commands:
5050
5151 # Validations also work on flags (when they have arguments)
5252 validate : file_exists
53+
54+ - name : build
55+ environment_variables :
56+ - name : build_dir
57+ help : Path to the build directory
58+ default : release
59+
60+ # Validations also work on environment variables
61+ validate : dir_exists
5362` ` ` `
5463
5564
@@ -97,5 +106,28 @@ must be an existing file
97106
98107````
99108
109+ ### ` $ ./validate build `
110+
111+ ```` shell
112+ validation error in environment variable BUILD_DIR:
113+ must be an existing directory
114+
115+
116+ ````
117+
118+ ### ` $ BUILD_DIR=src ./validate build `
119+
120+ ```` shell
121+ # this file is located in 'src/build_command.sh'
122+ # code for 'validate build' goes here
123+ # you can edit it freely and regenerate (it will not be overwritten)
124+ args: none
125+
126+ environment variables:
127+ - $BUILD_DIR = src
128+
129+
130+ ````
131+
100132
101133
Original file line number Diff line number Diff line change @@ -27,3 +27,11 @@ commands:
2727 # Validations also work on flags (when they have arguments)
2828 validate : file_exists
2929
30+ - name : build
31+ environment_variables :
32+ - name : build_dir
33+ help : Path to the build directory
34+ default : release
35+
36+ # Validations also work on environment variables
37+ validate : dir_exists
Original file line number Diff line number Diff line change 1+ echo " # this file is located in 'src/build_command.sh'"
2+ echo " # code for 'validate build' goes here"
3+ echo " # you can edit it freely and regenerate (it will not be overwritten)"
4+ inspect_args
Original file line number Diff line number Diff line change @@ -14,3 +14,6 @@ bashly generate
1414./validate calc A
1515./validate calc 1 B
1616./validate calc 1 2 --save no-such-file.txt
17+
18+ ./validate build
19+ BUILD_DIR=src ./validate build
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ created src/lib/validations/validate_not_empty.sh
66+ bashly generate
77creating user files in src
88created src/calc_command.sh
9+ created src/build_command.sh
910created ./validate
1011run ./validate --help to test your bash script
1112+ ./validate calc 1 2 --save README.md
@@ -25,3 +26,15 @@ must be an integer
2526+ ./validate calc 1 2 --save no-such-file.txt
2627validation error in --save PATH:
2728must be an existing file
29+ + ./validate build
30+ validation error in environment variable BUILD_DIR:
31+ must be an existing directory
32+ + BUILD_DIR=src
33+ + ./validate build
34+ # this file is located in 'src/build_command.sh'
35+ # code for 'validate build' goes here
36+ # you can edit it freely and regenerate (it will not be overwritten)
37+ args: none
38+
39+ environment variables:
40+ - $BUILD_DIR = src
You can’t perform that action at this time.
0 commit comments