Elektra  0.8.23
Plugin: enum

The enum plugin checks string values of Keys by comparing it against a list of valid values.

Usage

The plugin checks every Key in the Keyset for the Metakey check/enum containing a list with the syntax `'string1', 'string2', 'string3', ..., 'stringN'` and compares each value with the string value of the Key. If no match is found an error is returned.

Alternatively, if check/enum starts with #, a meta array check/enum is used. For example:

check/enum = #3
check/enum/#0 = small
check/enum/#1 = middle
check/enum/#2 = large
check/enum/#3 = huge

Furthermore check/enum/multi may contain a separator character, that separates multiple allowed occurrences. For example:

check/enum/multi = _

Then the value middle_small would validate. But middle_small_small would fail because every entry might only occur once.

## Example

1 # Backup-and-Restore:/examples/enum
2 
3 sudo kdb mount enum.ecf /examples/enum enum dump
4 
5 # valid initial value + setup valid enum list
6 kdb set /examples/enum/value middle
7 kdb setmeta user/examples/enum/value check/enum "'low', 'middle', 'high'"
8 
9 # should succeed
10 kdb set /examples/enum/value low
11 
12 # should fail with error 121
13 kdb set /examples/enum/value no
14 # RET:5
15 # ERROR:121

Or with multi-enums:

1 # valid initial value + setup array with valid enums
2 kdb set /examples/enum/multivalue middle_small
3 kdb setmeta user/examples/enum/multivalue check/enum/#0 small
4 kdb setmeta user/examples/enum/multivalue check/enum/#1 middle
5 kdb setmeta user/examples/enum/multivalue check/enum/#2 large
6 kdb setmeta user/examples/enum/multivalue check/enum/#3 huge
7 kdb setmeta user/examples/enum/multivalue check/enum/multi _
8 kdb setmeta user/examples/enum/multivalue check/enum "#3"
9 
10 # should succeed
11 kdb set /examples/enum/multivalue ___small_middle__
12 
13 # should fail with error 121
14 kdb set /examples/enum/multivalue ___all_small__
15 # RET:5
16 # ERROR:121
17 
18 # cleanup
19 kdb rm -r /examples/enum
20 sudo kdb umount /examples/enum

Limitations

You cannot give enum values specific values. If you only want to check for numerical values, the plugin range is better suited.