-
Notifications
You must be signed in to change notification settings - Fork 4
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 #171 from choria-io/170
(#170) Support including definitions
- Loading branch information
Showing
11 changed files
with
225 additions
and
49 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
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 |
---|---|---|
|
@@ -7,6 +7,31 @@ pre = "<b>4. </b>" | |
|
||
Some features are ongoing experiments and not part of the supported feature set, this section will call them out. | ||
|
||
## Including other definitions | ||
|
||
Since version 0.10.0 an entire definition can be included from another file or just the commands in a parent. | ||
|
||
```yaml | ||
name: include | ||
description: An include based app | ||
version: 0.2.2 | ||
author: [email protected] | ||
|
||
include_file: sample-app.yaml | ||
``` | ||
Here we include the entire application from another file but we override the name, description, version and author. | ||
A specific `parent` can load all it's commands from a file: | ||
|
||
```yaml | ||
- name: include | ||
type: parent | ||
include_file: go.yaml | ||
``` | ||
|
||
In this case the go.yaml would be the full `parent` definition. | ||
|
||
## Form based data generation wizards | ||
|
||
The general flow of applications is to expose Arguments and Flags when then can be used in templates to create files | ||
|
@@ -147,41 +172,6 @@ above) and will only ask this `thing` when the user opted to add accounts: | |
conditional: Input.accounts != nil | ||
``` | ||
|
||
## Argument and Flag Validations | ||
One might need to ensure that the input provided by a user passes some validation, for example when passing commands | ||
to shell scripts one has to be careful about [Shell Injection](https://en.wikipedia.org/wiki/Code_injection#Shell_injection). | ||
We support custom validators on Arguments and Flags using the [Expr Language](https://expr.medv.io/docs/Language-Definition) | ||
{{% notice secondary "Version Hint" code-branch %}} | ||
This is available since version `0.8.0`. | ||
{{% /notice %}} | ||
|
||
Based on the Getting Started example that calls `cowsay` we might wish to limit the length of the message to what | ||
would work well with `cowsay` and also ensure there is no shell escaping happening. | ||
|
||
```yaml | ||
arguments: | ||
- name: message | ||
description: The message to display | ||
required: true | ||
validate: len(value) < 20 && is_shellsafe(value) | ||
``` | ||
We support the standard `expr` language grammar - that has a large number of functions that can assist the | ||
validation needs - we then add a few extra functions that makes sense for operation teams. | ||
|
||
In each case accessing `value` would be the value passed from the user | ||
|
||
| Function | Description | | ||
|----------------------|---------------------------------------------------------------| | ||
| `isIP(value)` | Checks if `value` is an IPv4 or IPv6 address | | ||
| `isIPv4(value)` | Checks if `value` is an IPv4 address | | ||
| `isIPv6(value)` | Checks if `value` is an IPv6 address | | ||
| `isInt(value)` | Checks if `value` is an Integer | | ||
| `isFloat(value)` | Checks if `value` is a Float | | ||
| `isShellSafe(value)` | Checks if `value` is attempting to to do shell escape attacks | | ||
|
||
## Compiled Applications | ||
|
||
It's nice that you do not need to compile App Builder apps into binaries as it allows for fast iteration, but sometimes | ||
|
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,44 @@ | ||
name: go | ||
description: Demonstrates basic features such as flags and arguments | ||
type: parent | ||
commands: | ||
# Demonstrates the use of arguments and flags, mixing in arguments for main | ||
# functionality and flags for optional behavior changes. | ||
# | ||
# Also uses Go templates to adjust the command based on the flags given and | ||
# checks input is valid. | ||
- name: required | ||
description: Greet someone by name, name+surname with a customizable greeting | ||
type: exec | ||
# Here we use arguments for the name and surname, the name is required but surname is optional. | ||
arguments: | ||
- name: name | ||
description: The name of the person to greet | ||
required: true | ||
validate: len(value) < 20 | ||
- name: surname | ||
description: An optional surname of the person to greet | ||
# We add an optional flag to override the "Hello" greeting | ||
# It accepts only one of the 3 valid values | ||
flags: | ||
- name: greeting | ||
description: The greeting to use instead of Hello | ||
default: Hello | ||
env: GREETING | ||
short: g | ||
enum: | ||
- Hello | ||
- Morning | ||
- Halo | ||
|
||
# We use go templates and the default + require functions to ensure users do not set empty | ||
# strings such as "sample basics required ''" which would set the name to an empty string, | ||
# in that case we would fail stating a name is required. | ||
# | ||
# In the case of an empty greeting, we fall back to the default "Hello" | ||
command: | | ||
{{ if .Arguments.surname }} | ||
echo '{{ .Flags.greeting }} {{.Arguments.surname}}, {{ require .Arguments.name "a name is required" }} {{.Arguments.surname}}' | ||
{{ else }} | ||
echo '{{ .Flags.greeting }} {{ require .Arguments.name "a name is required" }}' | ||
{{ end }} |
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,6 @@ | ||
name: include | ||
description: An include based app | ||
version: 0.2.2 | ||
author: [email protected] | ||
|
||
include_file: sample-app.yaml |
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
Oops, something went wrong.