Skip to content

Commit 7690098

Browse files
committed
- Add hooks example
1 parent 3df4a2d commit 7690098

File tree

13 files changed

+92
-4
lines changed

13 files changed

+92
-4
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
6262
- [yaml](yaml#readme) - using the YAML reading functions
6363
- [completions](completions#readme) - adding bash completion functionality
6464
- [validations](validations#readme) - adding argument validation functions
65+
- [hooks](hooks#readme) - adding before/after hooks
6566

6667
## Other Examples
6768

examples/colors/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ $ bashly generate
1313
$ bashly generate
1414
```
1515

16-
The `bashly add colors` command, simply created the [src/lib/colors.sh]
17-
(src/lib/colors.sh) file, with useful color functions that will be
18-
automatically included in the generated script.
16+
The `bashly add colors` command, simply created the
17+
[src/lib/colors.sh](src/lib/colors.sh) file, with useful color functions that
18+
will be automatically included in the generated script.
1919

2020
See the manually edited [src/root_command.sh](src/root_command.sh) for usage
2121
examples.

examples/hooks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hooks

examples/hooks/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Before/After Hooks Example
2+
3+
This example demonstrates how to run common code before or after executing any
4+
command.
5+
6+
This example was generated with:
7+
8+
```bash
9+
$ bashly init
10+
# ... now edit src/bashly.yml to match the example ...
11+
$ bashly add hooks
12+
$ bashly generate
13+
```
14+
15+
<!-- include: src/root_command.sh -->
16+
17+
-----

examples/hooks/src/after.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## after hook
2+
##
3+
## Any code here will be placed inside an `after_hook()` function and called
4+
## after running any command.
5+
##
6+
## You can safely delete this file if you do not need it.
7+
echo "==[ After Hook Called ]=="

examples/hooks/src/bashly.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: hooks
2+
help: Sample application that uses before/after hooks
3+
version: 0.1.0
4+
5+
flags:
6+
- long: --debug
7+
short: -d
8+
help: Enable debug mode

examples/hooks/src/before.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## before hook
2+
##
3+
## Any code here will be placed inside a `before_hook()` function and called
4+
## before running any command (but after processing its arguments).
5+
##
6+
## You can safely delete this file if you do not need it.
7+
echo "==[ Before Hook Called ]=="
8+
inspect_args

examples/hooks/src/initialize.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Code here runs inside the initialize() function
2+
## Use it for anything that you need to run before any other function, like
3+
## setting environment variables:
4+
## CONFIG_FILE=settings.ini
5+
##
6+
## Feel free to empty (but not delete) this file.

examples/hooks/src/root_command.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "# this file is located in 'src/root_command.sh'"
2+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
3+
inspect_args

examples/hooks/test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
bashly add hooks --force
6+
bashly generate
7+
8+
### Try Me ###
9+
10+
./hooks
11+
./hooks --debug

0 commit comments

Comments
 (0)