allow parameters to be missing, if not used

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-03-10 17:41:08 +01:00
parent dc2a49afe8
commit e1a5a26cbf
2 changed files with 26 additions and 11 deletions

View file

@ -207,6 +207,17 @@ __cdist_type_parameter_file()
echo "$(__cdist_type_parameter_dir "$1")/$2"
}
# Shorthand for required and optional
__cdist_type_parameter_required()
{
__cdist_type_parameter_file "$1/$__cdist_name_parameter_required"
}
__cdist_type_parameter_optional()
{
__cdist_type_parameter_file "$1/$__cdist_name_parameter_optional"
}
__cdist_type_from_object()
{
echo "${1%%/*}"

View file

@ -78,20 +78,24 @@ while [ $# -gt 0 ]; do
done
# Ensure required parameters are given
if [ -f "$(__cdist_type_parameter_required "$__cdist_type")" ]; then
while read required; do
if [ ! -f "${tempparameter}/${required}" ]; then
__cdist_usage "Missing required parameter $required"
fi
mv "${tempparameter}/${required}" "${__cdist_parameter_dir}"
done < "$(__cdist_type_parameter_file "$__cdist_type" "$__cdist_name_parameter_required")"
done < "$(__cdist_type_parameter_required "$__cdist_type")"
fi
# Allow optional parameters
if [ -f "$(__cdist_type_parameter_optional "$__cdist_type")" ]; then
while read optional; do
if [ -f "${tempparameter}/${optional}" ]; then
mv "${tempparameter}/${optional}" "${__cdist_parameter_dir}"
fi
done < "$(__cdist_type_parameter_file "$__cdist_type" "$__cdist_name_parameter_optional")"
done < "$(__cdist_type_parameter_optional "$__cdist_type")"
fi
# Error out on other paramaters
cd "${tempparameter}"