- infos = Information about the enum plugin is in keys below
- infos/author = Thomas Waser thoma.nosp@m.s.wa.nosp@m.ser@l.nosp@m.ibel.nosp@m.ektra.nosp@m..org
- infos/licence = BSD
- infos/provides = check
- infos/needs =
- infos/recommends =
- infos/placements = presetstorage
- infos/status = productive maintained unittest tested nodep libc
- infos/metadata = check/enum check/enum/# check/enum/multi
- infos/description = validates values against 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
4 # 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'"
11 kdb set /examples/enum/value low
13 # should fail with error 121
15 kdb set /examples/enum/value no
18 # The command set failed while accessing the key database with the info:
19 # Error (#121) occurred!
20 # Description: Validation failed
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
4 # valid initial value + setup array with valid enums
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"
16 kdb set /examples/enum/value ___small_middle__
18 # should fail with error 121
20 kdb set /examples/enum/value ___all_small__
23 # The command set failed while accessing the key database with the info:
24 # Error (#121) occurred!
25 # Description: Validation failed
31 kdb rm -r /examples/enum
32 sudo kdb umount /examples/enum