forked from PKU-ASAL/WASEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.sh
executable file
·64 lines (55 loc) · 1.31 KB
/
clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -e
OUTPUT_DIR=output
error() {
command printf '\033[1;31mError: %s\033[0m\n\n' "$1" 1>&2
}
usage() {
cat >&2 <<END_USAGE
clean.sh: remove and recreate empty "log" and "result" directories
USAGE:
clean.sh -[fi]
FLAGS:
-h, --help Prints help information
-i, --interactive Interactive mode
-f, --force Force remove output files and directories
END_USAGE
}
# parse command line options
while [ $# -gt 0 ]
do
arg="$1"
case "$arg" in
-h|--help)
usage
exit 1
;;
-f|--force)
shift # shift off the argument
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/log $OUTPUT_DIR/result
touch $OUTPUT_DIR/log/.placeholder $OUTPUT_DIR/result/.placeholder
exit 0
;;
-i|--interactive)
shift # shift off the argument
read -p "Are you sure you want to remove all output files and directories (rm -rf $OUTPUT_DIR)? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR/log $OUTPUT_DIR/result
touch $OUTPUT_DIR/log/.placeholder $OUTPUT_DIR/result/.placeholder
exit 0
fi
exit 1
;;
*)
error "Unknown option: '$arg'"
usage
exit 1
;;
esac
done
usage
exit 1