forked from ungleich-public/cdist
		
	[type/__uci] Allow omission of --value parameter if --state absent
This commit is contained in:
		
					parent
					
						
							
								55e7b32449
							
						
					
				
			
			
				commit
				
					
						a09120977f
					
				
			
		
					 4 changed files with 15 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -40,6 +40,14 @@ values_is=$(uci -s -N -d "${RS}" get "${option}" 2>/dev/null) || {
 | 
			
		|||
	exit 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if test -f "${__object:?}/parameter/value"
 | 
			
		||||
then
 | 
			
		||||
	should_file="${__object:?}/parameter/value"
 | 
			
		||||
else
 | 
			
		||||
	should_file='/dev/null'
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# strip off trailing newline
 | 
			
		||||
printf '%s' "${values_is}" \
 | 
			
		||||
| awk '
 | 
			
		||||
| 
						 | 
				
			
			@ -86,4 +94,4 @@ END {
 | 
			
		|||
 | 
			
		||||
	print state
 | 
			
		||||
}
 | 
			
		||||
' "${__object:?}/parameter/value" RS="${RS}" -
 | 
			
		||||
' "${should_file}" RS="${RS}" -
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,7 @@ REQUIRED PARAMETERS
 | 
			
		|||
-------------------
 | 
			
		||||
value
 | 
			
		||||
    The value to be set. Can be used multiple times.
 | 
			
		||||
    This parameter is allowed to be omitted if `--state` is `absent`.
 | 
			
		||||
 | 
			
		||||
    Due to the way cdist handles arguments, values **must not** contain newline
 | 
			
		||||
    characters.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,6 +43,11 @@ changes_required=false
 | 
			
		|||
case ${state_should}
 | 
			
		||||
in
 | 
			
		||||
	(present)
 | 
			
		||||
		test -s "${__object:?}/parameter/value" || {
 | 
			
		||||
			echo 'The parameter --value is required.' >&2
 | 
			
		||||
			exit 1
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		# NOTE: order is ignored so rearranged is also fine.
 | 
			
		||||
		in_list "${state_is}" 'present' 'rearranged' || changes_required=true
 | 
			
		||||
		;;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue