Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Create beautiful bash scripts from simple YAML configuration
- [Argument options](#argument-options)
- [Flag options](#flag-options)
- [Environment Variable options](#environment-variable-options)
- [Extensible Commands](#extensible-commands)
- [Real World Examples](#real-world-examples)
- [Contributing / Support](#contributing--support)

Expand Down Expand Up @@ -203,6 +204,7 @@ command and subcommands (under the `commands` definition).
`help` | The header text to display when using `--help`. This option can have multiple lines. In this case, the first line will be used as summary wherever appropriate.
`version` | The string to display when using `--version`. *Applicable only in the main command*.
`default` | Setting this to `true` on any command, will cause any unrecognized command line to be passed to this command. *Applicable only in subcommands*.
`extensible` | Specify that this command can be [externally extended](#extensible-commands).
`examples` | Specify an array of examples to show when using `--help`. Each example can have multiple lines.
`environment_variables` | Specify an array of [environment variables](#environment-variable-options) needed by your script.
`commands` | Specify the array of [commands](#command-options). Each command will have its own args and flags. Note: if `commands` is provided, you cannot specify flags or args at the same level.
Expand Down Expand Up @@ -262,6 +264,82 @@ set.
`required` | Specify if this variable is required.


## Extensible Commands

You may configure your generated bash script to delegate any unknown command
to an external executable, by setting the `extensible` option to either `true`,
or to a different external command.

This is similar to how `git` works. When you execute `git whatever`, the `git`
command will look for a file named `git-whatever` in the path, and execute it.

Note that this option cannot be specified together with the `default` option,
since both specify a handler for unknown commands.

Bashly supports two operation modes.

### Extension Mode (`extensible: true`)

By setting `extensible` to `true`, a specially named executable will be called
when an unknown command is called by the user.

Given this `bashly.yml` configuration:

```yaml
name: myscript
help: Example
version: 0.1.0
extensible: true

commands:
- name: upload
help: Upload a file
```

And this user command:

```
$ myscript something

```

The generated script will look for an executable named `myscript-something`
in the path. If found, it will be called.

See the [extensible example](examples/extensible)


### Delegate Mode (`extensible: <executable name>`)

By setting `extensible` to any string, unknown command calls by the user will
be delegated to the executable with that name.

Given this `bashly.yml` configuration:

```yaml
name: mygit
help: Example
version: 0.1.0
extensible: git

commands:
- name: push
help: Push to my repository
```

And this user command:

```
$ mygit status

```

The generated script will execute `git status`.

See the [extensible-delegate example](examples/extensible-delegate)



## Real World Examples

- [Rush][rush] - a Personal Package Manager
Expand Down
9 changes: 9 additions & 0 deletions Runfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,30 @@ end

def examples
[
"examples/catch_all/download",
"examples/catch_all_advanced/cli",
"examples/colors/colorly",
"examples/command-default/ftp",
"examples/command-groups/ftp",
"examples/commands-nested/cli",
"examples/commands/cli",
"examples/config-ini/configly",
"examples/custom-includes/download",
"examples/custom-strings/download",
"examples/default-values/convert",
"examples/dependencies/cli",
"examples/docker-like/docker",
"examples/environment-variables/cli",
"examples/extensible-delegate/mygit",
"examples/extensible/cli",
"examples/git-like/git",
"examples/minimal/download",
"examples/minus-v/cli",
"examples/multiline/multi",
"examples/whitelist/login",
"examples/yaml/yaml",
"spec/fixtures/workspaces/catch-all-no-args/download",
"spec/fixtures/workspaces/flag-args-with-dash/argflag",
"spec/fixtures/workspaces/short-command-code/rush",
]
end
Expand Down
1 change: 1 addition & 0 deletions examples/catch_all_advanced/cli
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/command-default/ftp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
"" )
ftp_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/command-groups/ftp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
ftp_usage
exit 1
Expand Down
3 changes: 3 additions & 0 deletions examples/commands-nested/cli
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_usage
exit 1
Expand Down Expand Up @@ -409,6 +410,7 @@ cli_dir_parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_dir_usage
exit 1
Expand Down Expand Up @@ -596,6 +598,7 @@ cli_file_parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_file_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/commands/cli
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/config-ini/configly
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
configly_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/dependencies/cli
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_usage
exit 1
Expand Down
3 changes: 3 additions & 0 deletions examples/docker-like/docker
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
docker_usage
exit 1
Expand Down Expand Up @@ -357,6 +358,7 @@ docker_container_parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
docker_container_usage
exit 1
Expand Down Expand Up @@ -531,6 +533,7 @@ docker_image_parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
docker_image_usage
exit 1
Expand Down
1 change: 1 addition & 0 deletions examples/environment-variables/cli
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ parse_requirements() {
shift $#
;;

# :command.command_fallback
* )
cli_usage
exit 1
Expand Down
7 changes: 7 additions & 0 deletions examples/extensible-delegate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extensible Delegate Command Example
==================================================

This example was generated with:

$ bashly init
$ bashly generate
Loading