-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
247 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Internal Run Example | ||
|
||
This example demonstrates how to utilize the internal `run` function in order | ||
to call other commands internally, using the same syntax as would be used by | ||
a user in the CLI. | ||
|
||
This example was generated with: | ||
|
||
```bash | ||
$ bashly init | ||
# ... now edit src/bashly.yml to match the example ... | ||
$ bashly generate | ||
# ... now edit the generated command files to match the example ... | ||
$ bashly generate | ||
``` | ||
|
||
<!-- include: src/build_command.sh --> | ||
<!-- include: src/test_command.sh --> | ||
<!-- include: src/deploy_command.sh --> | ||
|
||
----- | ||
|
||
## `bashly.yml` | ||
|
||
````yaml | ||
name: cli | ||
help: Internal run test | ||
version: 0.1.0 | ||
|
||
commands: | ||
- name: build | ||
help: Build code | ||
args: | ||
- name: env | ||
help: Build environment | ||
default: development | ||
allowed: [development, production] | ||
|
||
- name: test | ||
help: Test code | ||
flags: | ||
- long: --full | ||
help: Run all tests | ||
|
||
- name: deploy | ||
help: Deploy code | ||
flags: | ||
- long: --build | ||
help: Build before deploying | ||
- long: --test | ||
help: Test before deploying | ||
```` | ||
|
||
## `src/build_command.sh` | ||
|
||
````bash | ||
echo "BUILD complete" | ||
inspect_args | ||
echo | ||
```` | ||
|
||
|
||
## Output | ||
|
||
### `$ ./cli -h` | ||
|
||
````shell | ||
cli - Internal run test | ||
|
||
Usage: | ||
cli COMMAND | ||
cli [COMMAND] --help | -h | ||
cli --version | -v | ||
|
||
Commands: | ||
build Build code | ||
test Test code | ||
deploy Deploy code | ||
|
||
Options: | ||
--help, -h | ||
Show this help | ||
|
||
--version, -v | ||
Show version number | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ ./cli deploy -h` | ||
|
||
````shell | ||
cli deploy - Deploy code | ||
|
||
Usage: | ||
cli deploy [OPTIONS] | ||
cli deploy --help | -h | ||
|
||
Options: | ||
--build | ||
Build before deploying | ||
|
||
--test | ||
Test before deploying | ||
|
||
--help, -h | ||
Show this help | ||
|
||
|
||
|
||
```` | ||
|
||
### `$ ./cli deploy --build --test` | ||
|
||
````shell | ||
BUILD complete | ||
args: | ||
- ${args[env]} = production | ||
|
||
TEST complete | ||
args: | ||
- ${args[--full]} = 1 | ||
|
||
DEPLOY complete | ||
args: | ||
- ${args[--full]} = 1 | ||
|
||
|
||
```` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: cli | ||
help: Internal run test | ||
version: 0.1.0 | ||
|
||
commands: | ||
- name: build | ||
help: Build code | ||
args: | ||
- name: env | ||
help: Build environment | ||
default: development | ||
allowed: [development, production] | ||
|
||
- name: test | ||
help: Test code | ||
flags: | ||
- long: --full | ||
help: Run all tests | ||
|
||
- name: deploy | ||
help: Deploy code | ||
flags: | ||
- long: --build | ||
help: Build before deploying | ||
- long: --test | ||
help: Test before deploying |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "BUILD complete" | ||
inspect_args | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# We must record the `args` array to our local variables, due to the fact | ||
# that calling `run` will reset it. | ||
build=${args['--build']} | ||
test=${args['--test']} | ||
|
||
# Call other commands in the same way they would be called in the CLI. | ||
[[ $build ]] && run build production | ||
[[ $test ]] && run test --full | ||
|
||
# Perform the purpose of this command. | ||
echo "DEPLOY complete" | ||
inspect_args | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "TEST complete" | ||
inspect_args | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
bundle exec bashly generate | ||
|
||
### Try Me ### | ||
|
||
./cli -h | ||
./cli deploy -h | ||
./cli deploy --build --test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
+ bundle exec bashly generate | ||
creating user files in src | ||
skipped src/build_command.sh (exists) | ||
skipped src/test_command.sh (exists) | ||
skipped src/deploy_command.sh (exists) | ||
created ./cli | ||
run ./cli --help to test your bash script | ||
+ ./cli -h | ||
cli - Internal run test | ||
|
||
Usage: | ||
cli COMMAND | ||
cli [COMMAND] --help | -h | ||
cli --version | -v | ||
|
||
Commands: | ||
build Build code | ||
test Test code | ||
deploy Deploy code | ||
|
||
Options: | ||
--help, -h | ||
Show this help | ||
|
||
--version, -v | ||
Show version number | ||
|
||
+ ./cli deploy -h | ||
cli deploy - Deploy code | ||
|
||
Usage: | ||
cli deploy [OPTIONS] | ||
cli deploy --help | -h | ||
|
||
Options: | ||
--build | ||
Build before deploying | ||
|
||
--test | ||
Test before deploying | ||
|
||
--help, -h | ||
Show this help | ||
|
||
+ ./cli deploy --build --test | ||
BUILD complete | ||
args: | ||
- ${args[env]} = production | ||
|
||
TEST complete | ||
args: | ||
- ${args[--full]} = 1 | ||
|
||
DEPLOY complete | ||
args: | ||
- ${args[--full]} = 1 |