Elektra  0.8.19
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 sudo kdb mount enum.ecf /examples/enum enum dump
3 #
4 # valid initial value + setup valid enum list
5 #
6 kdb set /examples/enum/value middle
7 kdb setmeta user/examples/enum/value check/enum "'low', 'middle', 'high'"
8 #
9 # should succeed
10 #
11 kdb set /examples/enum/value low
12 #
13 # should fail with error 121
14 #
15 kdb set /examples/enum/value no
16 # RET:5
17 # ERRORS:121
18 # The command set failed while accessing the key database with the info:
19 # Error (#121) occurred!
20 # Description: Validation failed
21 # Ingroup: plugin
22 # Module: enum
23 #
24 # cleanup
25 #
26 kdb rm -r /examples/enum
27 sudo kdb umount /examples/enum

Or with multi-enums:

1 # Backup-and-Restore:/examples/enum
2 sudo kdb mount enum.ecf /examples/enum enum dump
3 #
4 # valid initial value + setup array with valid enums
5 #
6 kdb set /examples/enum/value middle_small
7 kdb setmeta user/examples/enum/value check/enum/#0 small
8 kdb setmeta user/examples/enum/value check/enum/#1 middle
9 kdb setmeta user/examples/enum/value check/enum/#2 large
10 kdb setmeta user/examples/enum/value check/enum/#3 huge
11 kdb setmeta user/examples/enum/value check/enum/multi _
12 kdb setmeta user/examples/enum/value check/enum "#3"
13 #
14 # should succeed
15 #
16 kdb set /examples/enum/value ___small_middle__
17 #
18 # should fail with error 121
19 #
20 kdb set /examples/enum/value ___all_small__
21 # RET:5
22 # ERRORS:121
23 # The command set failed while accessing the key database with the info:
24 # Error (#121) occurred!
25 # Description: Validation failed
26 # Ingroup: plugin
27 # Module: enum
28 #
29 # cleanup
30 #
31 kdb rm -r /examples/enum
32 sudo kdb umount /examples/enum