Skip to content

Commit e9d688c

Browse files
committed
add split config example
1 parent 4044383 commit e9d688c

File tree

11 files changed

+306
-6
lines changed

11 files changed

+306
-6
lines changed

examples/colors/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,18 @@ echo
6666
6767
```
6868

69+
### `$ NO_COLOR=1 ./colorly`
70+
71+
```shell
72+
Message Recevied:
73+
74+
=> hello colors
75+
==> hello colors
76+
===> hello colors
77+
78+
79+
80+
```
81+
6982

7083

examples/environment-variables/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ echo "# you can edit it freely and regenerate (it will not be overwritten)"
6060
inspect_args
6161
6262
echo "environment:"
63-
echo "- API_KEY=$API_KEY"
64-
echo "- ENVIRONMENT=$ENVIRONMENT"
65-
echo "- MY_SECRET=$MY_SECRET"
63+
echo "- API_KEY=${API_KEY:-}"
64+
echo "- ENVIRONMENT=${ENVIRONMENT:-}"
65+
echo "- MY_SECRET=${MY_SECRET:-}"
6666
6767
```
6868

examples/split-config/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src/download_command.sh
2+
src/initialize.sh
3+
cli

examples/split-config/README.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Split Config Example
2+
3+
Demonstrates how to separate your bashly.yml into several files, and load
4+
configuration data from other YAML files, or directly from a YAML front matter
5+
in your code.
6+
7+
This example was generated with:
8+
9+
```bash
10+
$ bashly init
11+
$ bashly generate
12+
# ... now edit all files in the src folder ...
13+
$ bashly generate
14+
```
15+
16+
<!-- include: src/download_command.yml src/upload_command.sh src/common_flags.yml -->
17+
18+
-----
19+
20+
## `bashly.yml`
21+
22+
```yaml
23+
name: cli
24+
help: Configuration splitting example
25+
version: 0.1.0
26+
27+
commands:
28+
# Import a command that is defined in another YAML file
29+
- import: src/download_command.yml
30+
31+
# Import a command that is defined in the front matter of its own shell
32+
# function.
33+
- import: src/upload_command.sh
34+
```
35+
36+
## `src/download_command.yml`
37+
38+
```yaml
39+
name: download
40+
short: d
41+
help: Download a file
42+
43+
args:
44+
- name: source
45+
required: true
46+
help: URL to download from
47+
- name: target
48+
help: "Target filename (default: same as source)"
49+
50+
flags:
51+
import: src/common_flags.yml
52+
53+
```
54+
55+
## `src/upload_command.sh`
56+
57+
```bash
58+
# This is a YAML front matter describing the command
59+
# It is imported to bashly.yml when running "bashly generate"
60+
61+
name: upload
62+
short: u
63+
help: Upload a file
64+
args:
65+
- name: source
66+
required: true
67+
help: File to upload
68+
69+
flags:
70+
import: src/common_flags.yml
71+
72+
---
73+
# Shell script starts here
74+
inspect_args
75+
76+
```
77+
78+
## `src/common_flags.yml`
79+
80+
```yaml
81+
- long: --force
82+
short: -f
83+
help: Overwrite existing files
84+
85+
```
86+
87+
88+
## Generated script output
89+
90+
### `$ ./cli`
91+
92+
```shell
93+
cli - Configuration splitting example
94+
95+
Usage:
96+
cli [command]
97+
cli [command] --help | -h
98+
cli --version | -v
99+
100+
Commands:
101+
download Download a file
102+
upload Upload a file
103+
104+
105+
106+
```
107+
108+
### `$ ./cli download -h`
109+
110+
```shell
111+
cli download - Download a file
112+
113+
Shortcut: d
114+
115+
Usage:
116+
cli download SOURCE [TARGET] [options]
117+
cli download --help | -h
118+
119+
Options:
120+
--help, -h
121+
Show this help
122+
123+
--force, -f
124+
Overwrite existing files
125+
126+
Arguments:
127+
SOURCE
128+
URL to download from
129+
130+
TARGET
131+
Target filename (default: same as source)
132+
133+
134+
135+
```
136+
137+
### `$ ./cli upload -h`
138+
139+
```shell
140+
cli upload - Upload a file
141+
142+
Shortcut: u
143+
144+
Usage:
145+
cli upload SOURCE [options]
146+
cli upload --help | -h
147+
148+
Options:
149+
--help, -h
150+
Show this help
151+
152+
--force, -f
153+
Overwrite existing files
154+
155+
Arguments:
156+
SOURCE
157+
File to upload
158+
159+
160+
161+
```
162+
163+
164+

examples/split-config/src/bashly.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: cli
2+
help: Configuration splitting example
3+
version: 0.1.0
4+
5+
commands:
6+
# Import a command that is defined in another YAML file
7+
- import: src/download_command.yml
8+
9+
# Import a command that is defined in the front matter of its own shell
10+
# function.
11+
- import: src/upload_command.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- long: --force
2+
short: -f
3+
help: Overwrite existing files
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: download
2+
short: d
3+
help: Download a file
4+
5+
args:
6+
- name: source
7+
required: true
8+
help: URL to download from
9+
- name: target
10+
help: "Target filename (default: same as source)"
11+
12+
flags:
13+
import: src/common_flags.yml
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This is a YAML front matter describing the command
2+
# It is imported to bashly.yml when running "bashly generate"
3+
4+
name: upload
5+
short: u
6+
help: Upload a file
7+
args:
8+
- name: source
9+
required: true
10+
help: File to upload
11+
12+
flags:
13+
import: src/common_flags.yml
14+
15+
---
16+
# Shell script starts here
17+
inspect_args

examples/split-config/test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f "src/download_command.sh"
4+
rm -f "src/initialize.sh"
5+
6+
set -x
7+
8+
bashly generate
9+
10+
### Try Me ###
11+
12+
./cli
13+
./cli download -h
14+
./cli upload -h

examples/yaml/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ server:
6464
## `src/root_command.sh`
6565

6666
```bash
67-
filename=${args[filename]}
68-
variable=${args[variable]}
69-
prefix=${args[--prefix]}
67+
filename=${args[filename]:-}
68+
variable=${args[variable]:-}
69+
prefix=${args[--prefix]:-}
7070
7171
if [[ $variable ]]; then
7272
eval "$(yaml_load "$filename" "$prefix")"

0 commit comments

Comments
 (0)