
\begin{DoxyItemize}
\item infos = Information about the enum plugin is in keys below
\item infos/author = Thomas Waser \href{mailto:thomas.waser@libelektra.org}{\tt thomas.\+waser@libelektra.\+org}
\item infos/licence = B\+S\+D
\item infos/provides = check
\item infos/needs =
\item infos/recommends =
\item infos/placements = presetstorage
\item infos/status = productive maintained unittest tested nodep libc
\item infos/metadata = check/enum check/enum/\# check/enum/multi
\item infos/description = validates values against enum
\end{DoxyItemize}

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

\subsection*{Usage}

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

Alternatively, if {\ttfamily check/enum} starts with {\ttfamily \#}, a meta array {\ttfamily check/enum} is used. For example\+: \begin{DoxyVerb}check/enum = #3
check/enum/#0 = small
check/enum/#1 = middle
check/enum/#2 = large
check/enum/#3 = huge
\end{DoxyVerb}


Furthermore {\ttfamily check/enum/multi} may contain a separator character, that separates multiple allowed occurrences. For example\+: \begin{DoxyVerb}check/enum/multi = _
\end{DoxyVerb}


Then the value {\ttfamily middle\+\_\+small} would validate. But {\ttfamily middle\+\_\+small\+\_\+small} would fail because every entry might only occur once.

\subsection*{Example}

``` \section*{Backup-\/and-\/\+Restore\+:/examples/enum}

sudo kdb mount enum.\+ecf /examples/enum enum dump \# \section*{valid initial value + setup valid enum list}

\# kdb set /examples/enum/value middle kdb setmeta user/examples/enum/value check/enum \char`\"{}'low', 'middle', 'high'\char`\"{} \# \section*{should succeed}

\# kdb set /examples/enum/value low \# \section*{should fail with error 121}

\# kdb set /examples/enum/value no \section*{R\+E\+T\+:5}

\section*{E\+R\+R\+O\+R\+S\+:121}

\section*{The command set failed while accessing the key database with the info\+:}

\section*{Error (\#121) occurred!}

\section*{Description\+: Validation failed}

\section*{Ingroup\+: plugin}

\section*{Module\+: enum}

\# \section*{cleanup}

\# kdb rm -\/r /examples/enum sudo kdb umount /examples/enum ``` Or with multi-\/enums\+: ``` \section*{Backup-\/and-\/\+Restore\+:/examples/enum}

sudo kdb mount enum.\+ecf /examples/enum enum dump \# \section*{valid initial value + setup array with valid enums}

\# kdb set /examples/enum/value middle\+\_\+small kdb setmeta user/examples/enum/value check/enum/\#0 small kdb setmeta user/examples/enum/value check/enum/\#1 middle kdb setmeta user/examples/enum/value check/enum/\#2 large kdb setmeta user/examples/enum/value check/enum/\#3 huge kdb setmeta user/examples/enum/value check/enum/multi \+\_\+ kdb setmeta user/examples/enum/value check/enum \char`\"{}\#3\char`\"{} \# \section*{should succeed}

\# kdb set /examples/enum/value \+\_\+\+\_\+\+\_\+small\+\_\+middle\+\_\+\+\_\+ \# \section*{should fail with error 121}

\# kdb set /examples/enum/value \+\_\+\+\_\+\+\_\+all\+\_\+small\+\_\+\+\_\+ \section*{R\+E\+T\+:5}

\section*{E\+R\+R\+O\+R\+S\+:121}

\section*{The command set failed while accessing the key database with the info\+:}

\section*{Error (\#121) occurred!}

\section*{Description\+: Validation failed}

\section*{Ingroup\+: plugin}

\section*{Module\+: enum}

\# \section*{cleanup}

\# kdb rm -\/r /examples/enum sudo kdb umount /examples/enum ``` 