Skip to content

Commit 1fcb671

Browse files
committed
update examples
1 parent 7a425c1 commit 1fcb671

File tree

31 files changed

+553
-75
lines changed

31 files changed

+553
-75
lines changed

examples/catch-all-advanced/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Catch All Advanced Example
22

3-
Demonstrates the advanced form of `catch_all`, where you can specify a help message .
3+
Demonstrates the advanced form of `catch_all`, where you can specify a help
4+
message.
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 generate
12+
```
413

514
-----
615

@@ -51,6 +60,8 @@ commands:
5160
required: true
5261
```
5362
63+
64+
5465
## Generated script output
5566
5667
### `$ ./cli`

examples/catch-all/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Demonstrates the use of the `catch_all` option, which will allows any command
44
to receive an arbitrary list of arguments.
55

6+
This example was generated with:
7+
8+
```bash
9+
$ bashly init
10+
# ... now edit src/bashly.yml to match the example ...
11+
$ bashly generate
12+
```
13+
614
-----
715

816
## `bashly.yml`
@@ -21,6 +29,8 @@ args:
2129
help: Message
2230
```
2331
32+
33+
2434
## Generated script output
2535
2636
### `$ ./download`

examples/colors/README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
Colors Example
2-
==================================================
1+
# Colors Example
32

4-
This example was generated with:
3+
This example demonstrates how to add color print functions.
54

6-
$ bashly init
7-
$ bashly add colors
8-
$ bashly generate
5+
This example was generated with:
96

10-
The `bashly add colors` command, simply created the [src/lib/colors.sh](src/lib/colors.sh) file, with useful color functions that will be automatically included in the generated script.
7+
```bash
8+
$ bashly init
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly add colors
11+
$ bashly generate
12+
# ... now edit src/root_command.sh ...
13+
$ bashly generate
14+
```
1115

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.
1219

20+
See the manually edited [src/root_command.sh](src/root_command.sh) for usage
21+
examples.
1322

14-
See the manually edited [src/root_command.sh](src/root_command.sh) for usage examples.
23+
<!-- include: src/root_command.sh -->
1524

1625
-----
1726

@@ -27,6 +36,21 @@ args:
2736
help: "Message to show [default: hello colors]"
2837
```
2938
39+
## `src/root_command.sh`
40+
41+
```bash
42+
message=${args[message]:-hello colors}
43+
44+
underlined "Message Recevied":
45+
echo
46+
echo " => $(green_bold "$message")"
47+
echo " ==> $(red_bold "$message")"
48+
echo " ===> $(blue_bold "$message")"
49+
echo
50+
51+
```
52+
53+
3054
## Generated script output
3155

3256
### `$ ./colorly`

examples/command-default/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Default Command Example
22

3-
Demonstrates how to set a command as the default command. This command can be executed without explicitly specifying the command name.
3+
Demonstrates how to set a command as the default command. This command can be
4+
executed without explicitly specifying the command name.
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 generate
12+
```
413

514
-----
615

@@ -36,6 +45,8 @@ commands:
3645
help: File to download
3746
```
3847
48+
49+
3950
## Generated script output
4051
4152
### `$ ./ftp`

examples/command-groups/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Command Groups Example
22

3-
Demonstrates how to visually group commands under their own caption. This is useful for scripts that contain many commands that provide different sets of functionality.
3+
Demonstrates how to visually group commands under their own caption. This is
4+
useful for scripts that contain many commands that provide different sets of
5+
functionality.
6+
7+
This example was generated with:
8+
9+
```bash
10+
$ bashly init
11+
# ... now edit src/bashly.yml to match the example ...
12+
$ bashly generate
13+
```
414

515
-----
616

@@ -44,6 +54,8 @@ commands:
4454
help: Delete login credentials to the config file
4555
```
4656
57+
58+
4759
## Generated script output
4860
4961
### `$ ./ftp`

examples/commands-nested/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ Demonstrates how to commands can be nested inside other commands.
44

55
This example was generated with:
66

7-
$ bashly init
8-
$ bashly generate
7+
```bash
8+
$ bashly init
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly generate
11+
```
912

1013
-----
1114

@@ -61,6 +64,8 @@ commands:
6164
args: *file_args # reuse args from the show command
6265
```
6366
67+
68+
6469
## Generated script output
6570
6671
### `$ ./cli`

examples/commands/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ Demonstrates how to build a script that supports sub-commands.
44

55
This example was generated with:
66

7-
$ bashly init
8-
$ bashly generate
7+
```bash
8+
$ bashly init
9+
$ bashly generate
10+
```
911

1012
-----
1113

@@ -67,6 +69,8 @@ commands:
6769
help: Password to use for logging in
6870
```
6971
72+
73+
7074
## Generated script output
7175
7276
### `$ ./cli`

examples/completions/README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ Demonstrates how to build a script that supports bash completions.
44

55
This example was generated with:
66

7-
$ bashly init
8-
$ bashly add comp function
9-
$ bashly generate
7+
```bash
8+
$ bashly init
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly add comp function
11+
$ bashly generate
12+
# ... now edit src/completions_command.sh ...
13+
$ bashly generate
14+
```
15+
16+
<!-- include: src/completions_command.sh -->
1017

1118
-----
1219

@@ -72,6 +79,22 @@ commands:
7279
help: Password to use for logging in
7380
```
7481
82+
## `src/completions_command.sh`
83+
84+
```bash
85+
# Call the `send_completions` function which was added by running:
86+
#
87+
# $ bashly add comp function
88+
#
89+
# Users can now enable bash completion for this script by running:
90+
#
91+
# $ eval "$(cli completions)"
92+
#
93+
send_completions
94+
95+
```
96+
97+
7598
## Generated script output
7699

77100
### `$ ./cli`

examples/config-ini/README.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# Config Example
22

3+
Demonstrates how to add functions for reading and writing INI files.
4+
35
This example was generated with:
46

5-
$ bashly init
6-
$ bashly add config
7-
$ bashly generate
7+
```bash
8+
$ bashly init
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly add config
11+
$ bashly generate
12+
# ... now edit all files in the src folder ...
13+
$ bashly generate
14+
```
815

916
Running the `bashly add config` command simply added the [src/lib/config.sh](src/lib/config.sh) file, which includes functions for reading and writing values from an INI file.
1017

1118
See the files in the [src](src) folder for usage examples.
1219

20+
<!-- include: config.ini src/get_command.sh src/list_command.sh src/set_command.sh -->
21+
1322
-----
1423

1524
## `bashly.yml`
@@ -52,6 +61,58 @@ commands:
5261
help: Show the entire config file
5362
```
5463
64+
## `config.ini`
65+
66+
```ini
67+
; comments are allowed
68+
hello = world
69+
bashly = works
70+
71+
72+
```
73+
74+
## `src/get_command.sh`
75+
76+
```bash
77+
# Using the standard library (lib/config.sh) to show a value from the config
78+
79+
key="${args[key]}"
80+
if config_has_key "$key" ; then
81+
config_get "$key"
82+
else
83+
echo "No such key: $key"
84+
fi
85+
86+
# Example of how to assign the config value to a variable:
87+
# result=$(config_get "${args[key]}")
88+
# echo $result
89+
90+
91+
```
92+
93+
## `src/list_command.sh`
94+
95+
```bash
96+
# Using the standard library (lib/config.sh) to show the entire config file
97+
config_show
98+
99+
# Or to iterate through keys
100+
for key in $(config_keys) ; do
101+
echo "$key === $(config_get "$key")"
102+
done
103+
104+
```
105+
106+
## `src/set_command.sh`
107+
108+
```bash
109+
# Using the standard library (lib/config.sh) to store a value to the config
110+
config_set "${args[key]}" "${args[value]}"
111+
echo "saved: ${args[key]} = ${args[value]}"
112+
113+
```
114+
115+
55116
## Generated script output
56117

57118
### `$ ./configly -h`

0 commit comments

Comments
 (0)