Skip to content

Commit 68c35b0

Browse files
committed
re-add the original heredoc example
1 parent dd95436 commit 68c35b0

File tree

9 files changed

+107
-0
lines changed

9 files changed

+107
-0
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ Each of these examples demonstrates one aspect or feature of bashly.
5858
## Other Examples
5959

6060
- [heredoc](heredoc#readme) - using heredoc strings
61+
- [heredoc-alt](heredoc-alt#readme) - using heredoc strings in the lib directory
6162
- [settings](settings#readme) - using the settings.yml file to adjust bashly's behavior

examples/heredoc-alt/.gitignore

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

examples/heredoc-alt/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Heredoc Alternative Example
2+
3+
This example shows how you can use *Here document* (heredoc) constructs without
4+
forcing the entire script to use tab indentation.
5+
6+
Code in the `src/lib` directory is injected to your script as is, so in cases
7+
where you must use heredocs, this is where you can.
8+
9+
This example was generated with:
10+
11+
```bash
12+
$ bashly init
13+
$ bashly add lib
14+
# ... now edit src/bashly.yml to match the example ...
15+
# ... now edit src/root_command.sh to match the example ...
16+
# ... now edit src/lib/heredocs.sh to match the example ...
17+
$ bashly generate
18+
```
19+
20+
<!-- include: src/root_command.sh src/lib/heredocs.sh -->
21+
22+
-----
23+
24+
## `bashly.yml`
25+
26+
```yaml
27+
name: cli
28+
help: Sample application showing the use of heredoc
29+
version: 0.1.0
30+
```
31+
32+
## `src/root_command.sh`
33+
34+
```bash
35+
text="$(message1)"
36+
echo "$text"
37+
```
38+
39+
## `src/lib/heredocs.sh`
40+
41+
```bash
42+
message1() {
43+
cat << EOF
44+
this is a
45+
multiline
46+
heredoc text
47+
EOF
48+
}
49+
50+
```
51+
52+
53+
## Generated script output
54+
55+
### `$ ./cli`
56+
57+
```shell
58+
multiline
59+
heredoc text
60+
this is
61+
 an indented
62+
  multiline text
63+
64+
65+
```
66+
67+
68+

examples/heredoc-alt/src/bashly.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: cli
2+
help: Sample application showing the use of heredoc
3+
version: 0.1.0
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 vairables:
4+
## CONFIG_FILE=settings.ini
5+
##
6+
## Feel free to empty (but not delete) this file.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
message1() {
2+
cat << EOF
3+
this is a
4+
multiline
5+
heredoc text
6+
EOF
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
text="$(message1)"
2+
echo "$text"

examples/heredoc-alt/test.sh

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

spec/approvals/examples/heredoc-alt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+ bashly generate
2+
creating user files in src
3+
skipped src/initialize.sh (exists)
4+
skipped src/root_command.sh (exists)
5+
created ./cli
6+
run ./cli --help to test your bash script
7+
+ ./cli
8+
this is a
9+
multiline
10+
heredoc text

0 commit comments

Comments
 (0)