File tree Expand file tree Collapse file tree 10 files changed +247
-10
lines changed Expand file tree Collapse file tree 10 files changed +247
-10
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
42
42
- [ commands-expose] ( commands-expose#readme ) - showing subcommands in the parent's help
43
43
- [ key-value-pairs] ( key-value-pairs#readme ) - parsing key=value arguments and flags
44
44
- [ command-examples-on-error] ( command-examples-on-error#readme ) - showing examples on error
45
+ - [ internal-run] ( internal-run#readme ) - calling other commands internally
45
46
46
47
## Customization
47
48
Original file line number Diff line number Diff line change @@ -52,16 +52,6 @@ commands:
52
52
# ## `$ ./cli download`
53
53
54
54
` ` ` ` shell
55
- # This file is located at 'src/download_command.sh'.
56
- # It contains the implementation for the 'cli download' command.
57
- # The code you write here will be wrapped by a function named 'cli_download_command()'.
58
- # Feel free to edit this file; your changes will persist when regenerating.
59
- args : none
60
-
61
- deps :
62
- - ${deps[git]} = /usr/bin/git
63
- - ${deps[http_client]} = /usr/bin/curl
64
- - ${deps[ruby]} = /home/vagrant/.rbenv/versions/3.3.6/bin/ruby
65
55
66
56
67
57
````
Original file line number Diff line number Diff line change
1
+ cli
Original file line number Diff line number Diff line change
1
+ # Internal Run Example
2
+
3
+ This example demonstrates how to utilize the internal ` run ` function in order
4
+ to call other commands internally, using the same syntax as would be used by
5
+ a user in the CLI.
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
+ # ... now edit the generated command files to match the example ...
14
+ $ bashly generate
15
+ ```
16
+
17
+ <!-- include: src/build_command.sh -->
18
+ <!-- include: src/test_command.sh -->
19
+ <!-- include: src/deploy_command.sh -->
20
+
21
+ -----
22
+
23
+ ## ` bashly.yml `
24
+
25
+ ```` yaml
26
+ name : cli
27
+ help : Internal run test
28
+ version : 0.1.0
29
+
30
+ commands :
31
+ - name : build
32
+ help : Build code
33
+ args :
34
+ - name : env
35
+ help : Build environment
36
+ default : development
37
+ allowed : [development, production]
38
+
39
+ - name : test
40
+ help : Test code
41
+ flags :
42
+ - long : --full
43
+ help : Run all tests
44
+
45
+ - name : deploy
46
+ help : Deploy code
47
+ flags :
48
+ - long : --build
49
+ help : Build before deploying
50
+ - long : --test
51
+ help : Test before deploying
52
+ ` ` ` `
53
+
54
+ # # `src/build_command.sh`
55
+
56
+ ` ` ` ` bash
57
+ echo "BUILD complete"
58
+ inspect_args
59
+ echo
60
+ ````
61
+
62
+
63
+ ## Output
64
+
65
+ ### ` $ ./cli -h `
66
+
67
+ ```` shell
68
+ cli - Internal run test
69
+
70
+ Usage:
71
+ cli COMMAND
72
+ cli [COMMAND] --help | -h
73
+ cli --version | -v
74
+
75
+ Commands:
76
+ build Build code
77
+ test Test code
78
+ deploy Deploy code
79
+
80
+ Options:
81
+ --help, -h
82
+ Show this help
83
+
84
+ --version, -v
85
+ Show version number
86
+
87
+
88
+
89
+ ````
90
+
91
+ ### ` $ ./cli deploy -h `
92
+
93
+ ```` shell
94
+ cli deploy - Deploy code
95
+
96
+ Usage:
97
+ cli deploy [OPTIONS]
98
+ cli deploy --help | -h
99
+
100
+ Options:
101
+ --build
102
+ Build before deploying
103
+
104
+ --test
105
+ Test before deploying
106
+
107
+ --help, -h
108
+ Show this help
109
+
110
+
111
+
112
+ ````
113
+
114
+ ### ` $ ./cli deploy --build --test `
115
+
116
+ ```` shell
117
+ BUILD complete
118
+ args:
119
+ - ${args[env]} = production
120
+
121
+ TEST complete
122
+ args:
123
+ - ${args[--full]} = 1
124
+
125
+ DEPLOY complete
126
+ args:
127
+ - ${args[--full]} = 1
128
+
129
+
130
+ ````
131
+
132
+
133
+
Original file line number Diff line number Diff line change
1
+ name : cli
2
+ help : Internal run test
3
+ version : 0.1.0
4
+
5
+ commands :
6
+ - name : build
7
+ help : Build code
8
+ args :
9
+ - name : env
10
+ help : Build environment
11
+ default : development
12
+ allowed : [development, production]
13
+
14
+ - name : test
15
+ help : Test code
16
+ flags :
17
+ - long : --full
18
+ help : Run all tests
19
+
20
+ - name : deploy
21
+ help : Deploy code
22
+ flags :
23
+ - long : --build
24
+ help : Build before deploying
25
+ - long : --test
26
+ help : Test before deploying
Original file line number Diff line number Diff line change
1
+ echo " BUILD complete"
2
+ inspect_args
3
+ echo
Original file line number Diff line number Diff line change
1
+ # We must record the `args` array to our local variables, due to the fact
2
+ # that calling `run` will reset it.
3
+ build=${args['--build']}
4
+ test=${args['--test']}
5
+
6
+ # Call other commands in the same way they would be called in the CLI.
7
+ [[ $build ]] && run build production
8
+ [[ $test ]] && run test --full
9
+
10
+ # Perform the purpose of this command.
11
+ echo " DEPLOY complete"
12
+ inspect_args
13
+
Original file line number Diff line number Diff line change
1
+ echo " TEST complete"
2
+ inspect_args
3
+ echo
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -x
4
+
5
+ bundle exec bashly generate
6
+
7
+ # ## Try Me ###
8
+
9
+ ./cli -h
10
+ ./cli deploy -h
11
+ ./cli deploy --build --test
Original file line number Diff line number Diff line change
1
+ + bundle exec bashly generate
2
+ creating user files in src
3
+ skipped src/build_command.sh (exists)
4
+ skipped src/test_command.sh (exists)
5
+ skipped src/deploy_command.sh (exists)
6
+ created ./cli
7
+ run ./cli --help to test your bash script
8
+ + ./cli -h
9
+ cli - Internal run test
10
+
11
+ Usage:
12
+ cli COMMAND
13
+ cli [COMMAND] --help | -h
14
+ cli --version | -v
15
+
16
+ Commands:
17
+ build Build code
18
+ test Test code
19
+ deploy Deploy code
20
+
21
+ Options:
22
+ --help, -h
23
+ Show this help
24
+
25
+ --version, -v
26
+ Show version number
27
+
28
+ + ./cli deploy -h
29
+ cli deploy - Deploy code
30
+
31
+ Usage:
32
+ cli deploy [OPTIONS]
33
+ cli deploy --help | -h
34
+
35
+ Options:
36
+ --build
37
+ Build before deploying
38
+
39
+ --test
40
+ Test before deploying
41
+
42
+ --help, -h
43
+ Show this help
44
+
45
+ + ./cli deploy --build --test
46
+ BUILD complete
47
+ args:
48
+ - ${args[env]} = production
49
+
50
+ TEST complete
51
+ args:
52
+ - ${args[--full]} = 1
53
+
54
+ DEPLOY complete
55
+ args:
56
+ - ${args[--full]} = 1
You can’t perform that action at this time.
0 commit comments