-
-
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.
Merge pull request #603 from DannyBen/revert/9167c49
Revert 9167c49 to allow calling `run ...` internally
- Loading branch information
Showing
13 changed files
with
261 additions
and
15 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,143 @@ | ||
# Internal Run Example | ||
|
||
This example demonstrates how to use the `run` function to call commands | ||
internally, using the exact same syntax as a user would in the CLI. This | ||
approach can be useful for chaining commands or reusing logic without | ||
duplicating code. | ||
|
||
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 | ||
``` | ||
|
||
Note that while this pattern of calling `run` internally is supported, you may | ||
want to consider using [lib functions] | ||
instead, for a more robust codebase. | ||
|
||
While this pattern of calling run internally is supported, you may want to | ||
consider using [lib functions](https://bashly.dannyb.co/usage/writing-your-scripts/#adding-common-functions) | ||
instead. lib functions can help create a more robust and maintainable codebase | ||
by centralizing reusable logic. | ||
|
||
<!-- 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
= view_marker | ||
|
||
> declare -g long_usage='' | ||
> declare -g -A args=() | ||
|
||
if catch_all_used_anywhere? | ||
|
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,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 |