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" 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() __cdist_type_from_object()
{ {
echo "${1%%/*}" echo "${1%%/*}"

View file

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