forked from ungleich-public/cdist
		
	add parameter checking to cdist_tree_wrapper
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								8f4def18b5
							
						
					
				
			
			
				commit
				
					
						a7505f10a4
					
				
			
		
					 1 changed files with 32 additions and 7 deletions
				
			
		| 
						 | 
					@ -46,25 +46,50 @@ fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mkdir -p "${__cdist_ddir}"
 | 
					mkdir -p "${__cdist_ddir}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# echo "I am $__cdist_myname and have been called with $@"
 | 
					echo "I am $__cdist_myname and have been called with $@"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Record (correct ;-) source
 | 
					# Record (correct ;-) source
 | 
				
			||||||
echo "${__cdist_manifest}" > "${__cdist_ddir}/${__cdist_name_object_source}"
 | 
					echo "${__cdist_manifest}" > "${__cdist_ddir}/${__cdist_name_object_source}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Record parameters to subdir
 | 
				
			||||||
 | 
					tempparams="${__cdist_tmp_dir}/params"
 | 
				
			||||||
 | 
					mkdir -p "$tempparams"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while [ $# -gt 0 ]; do
 | 
					while [ $# -gt 0 ]; do
 | 
				
			||||||
   opt="$1"; shift
 | 
					   opt="$1"; shift
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || __cdist_usage "Provide sane options"
 | 
					   echo "$opt" | grep -q "^--${__cdist_sane_regexp}\$" || \
 | 
				
			||||||
 | 
					      __cdist_usage "Provide sane options"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   opt_file="$(echo $opt | sed 's/^--//')"
 | 
					   opt_file="$(echo $opt | sed 's/^--//')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # FIXME: check for options supported by type - or leave it to the type?
 | 
					 | 
				
			||||||
   # I guess do it here, so we also check whether
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   [ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
 | 
					   [ $# -ge 1 ] || __cdist_usage "Missing value for $opt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   value="$1"; shift
 | 
					   value="$1"; shift
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   echo "${value}" > "${__cdist_ddir}/${opt_file}"
 | 
					   echo "${value}" > "${tempparams}/${opt_file}"
 | 
				
			||||||
 | 
					 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Ensure required parameters are given
 | 
				
			||||||
 | 
					while read required; do
 | 
				
			||||||
 | 
					   if [ ! -f "${tempparams}/${required}" ]; then
 | 
				
			||||||
 | 
					      __cdist_usage "Missing required parameter $required"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   mv "${tempparams}/${required}" "${__cdist_ddir}"
 | 
				
			||||||
 | 
					done < "$(__cdist_type_param_file "$__cdist_type" "$__cdist_name_type_params_required")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Allow optional parameters
 | 
				
			||||||
 | 
					while read optional; do
 | 
				
			||||||
 | 
					   if [ -f "${tempparams}/${opt_file}" ]; then
 | 
				
			||||||
 | 
					      mv "${tempparams}/${optional}" "${__cdist_ddir}"
 | 
				
			||||||
 | 
					   fi
 | 
				
			||||||
 | 
					done < "$(__cdist_type_param_file "$__cdist_type" "$__cdist_name_type_params_optional")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Error out on other paramaters
 | 
				
			||||||
 | 
					cd "${tempparams}"
 | 
				
			||||||
 | 
					other="$(ls)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ "$other" ]; then
 | 
				
			||||||
 | 
					   __cdist_usage "Unsupported parameter: $other"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue