Payload configuration
Often for more complex payloads you will want to give the user (or even just yourself) a simple way to change the payload behavior.
The easiest way to accomplish this is with standard variables.
Variables
Variables are assigned in payloads by setting a name to the value; for instance:
Variables can be set to strings or numbers, or even the output of other commands:
More examples of advanced variable use are in the chapter "Quotes and Expansions": Variables are extremely powerful!
Simple tests
To actually use the results of a configuration option, there are multiple ways to test how it is set.
The simplest test is to compare if a variable is equal to a fixed value:
This can, of course, also be combined with the else
construct:
Complex tests
More complex tests can be created with the case
statement:
The case
test allows us to match multiple options with a default final option if nothing else matches.
Check the chapter "Flow Control" for more detailed information about the if
and case
tests!
Payload configuration
When making a payload that accepts configuration options, we recommend placing all the options at the top of the payload so that they are easy to find. This way, users of your payload (or your own future self who has forgotten all the complexities of the payload) can easily change the setup.
It's also a good idea to include a description of the configuration variable, and how to use it, as a comment.
Whenever possible, provide a default value that makes sense.
Since a payload does not typically run interactively (the user will never see the output of echo
or similar), the LED
command is the primary way to communicate errors. For example continuing the payload from above,
Here we confirm the user has entered a sane configuration option, set the LED to error state, and exit the payload entirely.
Configuration names
There is no strict requirement when it comes to the naming of configuration variables, however it is a good idea to:
Keep them entirely upper case. This makes it easy to spot them in the code.
Give them meaningful names. This helps you remember them during the rest of the payload. Naming configuration variables
A
,B
, and so on is certainly possible, but don't.
Last updated