forked from mre/the-coding-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-missing-solutions
executable file
·66 lines (55 loc) · 1.47 KB
/
find-missing-solutions
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
#!/usr/bin/env bash
set -Eeuo pipefail
# only use colors if we are talking to a terminal
if [[ -t 1 ]]; then
error() { printf '\033[37;41m%s\033[0m\n' "$*" >&2; }
green() { printf '\033[0;32m%s\033[0m\n' "$*"; }
path() { printf '\033[0;35m%s\033[0m\n' "$*"; }
yellow() { printf '\033[0;33m%s\033[0m\n' "$*"; }
else
error() { printf '%s\n' "$*" >&2; }
green() { printf '%s\n' "$*"; }
path() { printf '%s\n' "$*"; }
yellow() { printf '%s\n' "$*"; }
fi
usage() {
cat <<USAGE
Find missing solutions for one or more programming languages.
$(yellow Usage:)
find-missing-solutions [option]... <extension>...
$(yellow Arguments:)
$(green extension) extension of the language you are interested in (e.g. $(yellow c), $(yellow java), $(yellow rs))
$(yellow Options:)
$(green -h, --help) display this help and exit
USAGE
}
if (($# == 0)); then
error 'Missing required extension.'
usage >&2
exit 64
fi
for arg in "$@"; do
if [[ "$arg" =~ ^-(h|-help)$ ]]; then
usage
exit 0
fi
done
shopt -s globstar nullglob
for ext in "$@"; do
# remove leading dot, if any
ext=${ext##*.}
# only print the header if we are talking to a terminal
if [[ -t 1 ]]; then
echo "The following $(yellow problems) have no solutions for $(green "$ext"):"
fi
for dir in ./problems/**/; do
if [[ -f "$dir/README.md" ]]; then
for file in "$dir"*."$ext"; do
if [[ -f "$file" ]]; then
continue 2
fi
done
path "$dir"
fi
done
done