I would like to enrich pgfkeys by the functionality of mandatory and recommended keys. If a mandatory key is not given, an error is shown. If a recommended key is not given, a warning is shown.
My idea is to have two handlers which can be used after the options have been processed:
\newcommand{\mycommand}[1][]{%
\pgfqkeys{/path}{#1,
key a/recommended,
key b/mandatory,
}%
% ...
}
This is as far as I am:
\documentclass{article}
\usepackage{pgfkeys}
\newcommand{\PackageName}{pgfkeys extended}
\makeatletter
\pgfqkeys{/handlers}{%
% ------- if given -------
if given/.code 2 args={%
\typeout{! path: \pgfkeyscurrentpath}%
\pgfkeys{\pgfkeyscurrentpath/.get=\tmp@value}%
\expandafter \ifx \expandafter \pgfkeysnovalue \tmp@value
#2%
\else
#1%
\fi
},
% ------- recommended -------
recommended/.style={%
if given=
\relax
\PackageWarning{\PackageName}{Recommended key `\pgfkeyscurrentkeyRAW' not given.}%
},
}
\makeatother
\pgfqkeys{/test}{%
hello/.initial,
hello/.value required,
}
\begin{document}
content\ldots
%\pgfqkeys{/test}{hello=true}
%\pgfkeysvalueof{/test/hello}
\pgfkeys{/test/hello/if given=10}
\pgfkeys{/test/hello/recommended}
\end{document}
The if given handler works fine on it's own.
But when it is called by the recommended handler \pgfkeyscurrentpath is empty.
I could change the recommended handler to a custom code instead of a style, save the \pgfkeyscurrentpath in a command before calling if given and then inside of if given check whether this command has been defined. If it is I use it, if it's not I use \pgfkeyscurrentpath. And in the end I mustn't forget to reset that command.
But that seems overly complicated. Isn't there an easier solution?
And if I can't use my own handler here in a style, do I need to be careful that some of TikZ's keys can not be used in a style either?