commit fedf0cb49d4fc034be73ccca459863bd04c8bf80
parent eb16c6d143df69eefd25496ef74885bb00e25c56
Author: Anton Konyahin <me@konyahin.xyz>
Date: Tue, 13 Jun 2023 22:27:07 +0300
command for files removing
Diffstat:
M | tagger | | | 49 | +++++++++++++++++++++++++++++++++++++++++-------- |
M | test.sh | | | 30 | +++++++++++++++++++++++++----- |
2 files changed, 66 insertions(+), 13 deletions(-)
diff --git a/tagger b/tagger
@@ -25,8 +25,8 @@ check () {
desc="$3"
pexist "$value" "$desc"
-
shift 3
+
for chk in "$@"
do
"$chk" "$value" "$desc"
@@ -35,6 +35,25 @@ check () {
[ -n "$name" ] && eval "$name=$value"
}
+check_all () {
+ name="$1"
+ vars="$2"
+ desc="$3"
+
+ pexist "$vars" "$desc"
+ shift 3
+
+ for chk in "$@"
+ do
+ for var in $vars
+ do
+ "$chk" "$var" "$desc"
+ done
+ done
+
+ [ -n "$name" ] && eval "$name=\"$vars\""
+}
+
pexist () {
[ -z "$1" ] &&
err "$2 should be specified"
@@ -98,9 +117,11 @@ init_tagger () {
##
add_file () {
check "" "$1" "tagger folder" pdir pbase
- check file "$3" file pfile
+ #check file "$3" file pfile
+ shift 2
+ check_all files "$*" files pfile
- mv "$file" "$BASE"
+ mv "$files" "$BASE"
}
## tagger _folder_ tag _file_ _tag_
@@ -146,6 +167,17 @@ path () {
echo "$BASE/$file"
}
+## tagger _folder_ rm _file_
+## remove file from tagger
+##
+remove () {
+ check "" "$1" "tagger folder" pdir pbase
+ check file "$3" file ptagged
+
+ rm -f "$BASE"/../*/"$file"
+ rm "$BASE/$file"
+}
+
# Process arguments
SCRIPT=$(dirname "$0")/tagger
@@ -156,10 +188,11 @@ COMMAND="$2"
case "$COMMAND" in
init) init_tagger "$@" ;;
- add) add_file "$@" ;;
- tag) tag_file "$@" ;;
- untag) untag_file "$@" ;;
- ls) list "$@" ;;
- path) path "$@" ;;
+ add) add_file "$@" ;;
+ tag) tag_file "$@" ;;
+ untag) untag_file "$@" ;;
+ ls) list "$@" ;;
+ path) path "$@" ;;
+ rm) remove "$@" ;;
*) err "Unknown command $COMMAND" ;;
esac
diff --git a/test.sh b/test.sh
@@ -26,12 +26,16 @@ test () {
}
tmp_file () {
- FILE=$(mktemp /tmp/tagger-test-file-XXXXXX)
- BASENAME=$(basename "$FILE")
-}
+ eval "FILE$1=$(mktemp /tmp/tagger-test-file-XXXXXX)"
+ eval "BASENAME$1=$(basename $FILE$1)"
+}
+
+tmp_dir () {
+ FOLDER=$(mktemp -d /tmp/tagger-test-XXXXXX)
+ LS_FOLDER="&& cd $FOLDER && find ."
+}
-FOLDER=$(mktemp -d /tmp/tagger-test-XXXXXX)
-LS_FOLDER="&& cd $FOLDER && find ."
+tmp_dir
test "init" "./tagger $FOLDER init $LS_FOLDER" \
".
@@ -64,4 +68,20 @@ test "ls files" "./tagger $FOLDER ls" "$BASENAME"
test "path file" "./tagger $FOLDER path $BASENAME" "$FOLDER/.base/$BASENAME"
+test "remove file" "./tagger $FOLDER rm $BASENAME $LS_FOLDER" \
+".
+./.base
+./a"
+
+tmp_file
+./tagger "$FOLDER" add "$FILE"
+./tagger "$FOLDER" tag "$BASENAME" test
+
+test "remove tagged file" "./tagger $FOLDER rm $BASENAME $LS_FOLDER" \
+".
+./.base
+./a
+./test"
+
+# clean up
rm -rf "$FOLDER"