clarify relation between line and regex

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-09-20 17:35:14 +02:00
parent fd490b39f1
commit 9e40d7bc91
2 changed files with 26 additions and 4 deletions

View file

@ -20,8 +20,10 @@
# #
file="/$__object_id" file="/$__object_id"
regex=""
state_should="present" state_should="present"
[ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file") [ -f "$__object/parameter/file" ] && file=$(cat "$__object/parameter/file")
[ -f "$__object/parameter/regex" ] && regex=$(cat "$__object/parameter/regex")
[ -f "$__object/parameter/state" ] && state_should=$(cat "$__object/parameter/state") [ -f "$__object/parameter/state" ] && state_should=$(cat "$__object/parameter/state")
state_is="$(cat "$__object/explorer/state")" state_is="$(cat "$__object/explorer/state")"
@ -41,7 +43,18 @@ case "$state_should" in
;; ;;
absent) absent)
echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\"" if [ "$regex" -a "$line" ]; then
echo "Mutally exclusive parameters regex and line given for state absent" >&2
exit 1
fi
[ "$line" ] && regex="^$line\$"
cat << eof
tmp=\$(mktemp)
sed '/$regex/d' "$file" > \$tmp && cat "\$tmp" > "$file" && rm -f "\$tmp"
eof
#echo "echo q | ex -c \"/${line}/d|w|q\" \"${file}\""
;; ;;
*) *)
echo "Unknown state: $state_should" >&2 echo "Unknown state: $state_should" >&2

View file

@ -23,11 +23,20 @@ state::
line:: line::
Specifies the line which should be absent or present Specifies the line which should be absent or present
Must be present, if state is present. Must be present, if state is present.
Must not be combined with regex, if state is absent.
regex:: regex::
If supplied, search for this regex. If state is present, search for this pattern and add
Otherwise entire line must be matched. given line, if the given regular expression does not match.
In case of absent, ensure all lines matching the
regular expression are absent (cannot be combined with
the line parameter, if state is absent).
If the regular expression contains / (slashes), they need
to be escaped with \ (backslash): / becomes \/.
file:: file::
If supplied, use this as the destination file. If supplied, use this as the destination file.