It is sometimes useful to permit the end-user to modify certain characteristics of a pattern, such as whether to enable features that may be costly, or to change a set of default paths or package names. This is enabled with pattern configuration blocks. Pattern configuration is new in Foundation 7.2/TPL 1.2.
Configuration block definition
configuration blocks are top-level elements. Like other elements, they have a name and a version number. Pattern modules can import configuration blocks from other modules, using the usual version numbering conventions.
The form of a configuration block is:
configuration name version
config_name := config_value;
...
end configuration;
Configuration items are given a human-readable description to be shown in the user interface, an identifier to use in patterns, and a default value. The default value is the value used if the configuration item has not been changed by the user. It also determines the type of the configuration item – the user interface will only allow the user to change the setting to a value with the same type. The valid types for configuration items are text string, integer, boolean, list of strings, and list of integers.
This example shows a number of configuration settings:
configuration MyConfig 1.0
a_flag := true;
command := "sudo rm -rf /";
port := 12345;
paths := [ "/usr/bin", "/usr/local/bin" ];
end configuration;
Using configuration settings
Configuration settings are used in patterns by giving the scoped name of the configuration block, followed by the configuration setting name:
if MyConfig.a_flag then
result := discovery.runCommand(host, MyConfig.command);
end if
Types of default empty lists
The types of configurations items can usually be inferred from the type of the default value. However, if the default value of a configuration item is an empty list, the system cannot know whether it is a list of text strings or a list of integers. To tell the system the type of such a configuration item, an example of the type should be provided in parentheses after the empty list:
empty_string_list := [ ] ("");
empty_number_list := [ ] (0);