-
-
Notifications
You must be signed in to change notification settings - Fork 544
/
check_required_files_present
executable file
·84 lines (71 loc) · 2.22 KB
/
check_required_files_present
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
missing_files=0
unneeded_files=0
verbose_progress='false'
if [[ ! -d exercises ]]; then
echo '"exercises" directory not found, make sure you are running from the repository root' >&2
exit 1
fi
function show_progress {
if [[ "${verbose_progress}" == 'true' ]]; then
printf '.'
fi
}
function require_file {
local filename=$1
if [[ ! -f "${filename}" ]]; then
echo "required file missing: ${filename}" >&2
(( ++missing_files ))
fi
}
function reject_file {
filename=$1
if [[ -f "${filename}" ]]; then
echo "unneeded file should be removed: ${filename}" >&2
(( ++unneeded_files ))
fi
}
function require_file_or_alternative {
filename=$1
alternative_filename=$2
if [[ ! -f "${filename}" && ! -f "${alternative_filename}" ]]; then
echo "required file missing: ${filename} or ${alternative_filename}" >&2
(( ++missing_files ))
elif [[ -f "${filename}" && -f "${alternative_filename}" ]]; then
echo "one of these two files should be removed: ${filename} or ${alternative_filename}" >&2
(( ++unneeded_files ))
fi
}
function check_directory {
directory=$1
for exercise_directory in "${directory}"/*; do
show_progress
# only two possibilities are allowed:
# 1. legacy: only description.md
# 2. migrated to new format: description.md is gone,
# and only instructions.md and introduction.md exist.
desc="${exercise_directory}/description.md"
inst="${exercise_directory}/instructions.md"
intro="${exercise_directory}/introduction.md"
require_file_or_alternative "${desc}" "${inst}"
if [[ -f "${inst}" ]]; then
require_file "${intro}"
elif [[ -f "${desc}" ]]; then
reject_file "${intro}"
fi
require_file "${exercise_directory}/metadata.toml"
done
}
if [[ "$1" == "-p" || "$1" == "--progress" ]]; then
verbose_progress="true"
fi
check_directory 'exercises'
if [[ "${verbose_progress}" == 'true' ]]; then
echo
echo "done: ${missing_files} files missing and ${unneeded_files} unneeded files."
fi
if (( missing_files || unneeded_files )); then
exit 1
else
exit 0
fi