-
Notifications
You must be signed in to change notification settings - Fork 3
/
debugit.sh
executable file
·42 lines (35 loc) · 1.19 KB
/
debugit.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
#!/bin/bash
# Magical command that will output the missing objects
#
# node_modules/.bin/elm make src/Main.elm --output=/dev/null 2>&1 \
# | command grep 'cannot find a `.*`' \
# | sed 's/.*`\([^`]*\)`.*/\1/' \
# | sort \
# | uniq \
# | paste -sd "," \
# | sed "s/,/, /g"
# Add missing import from the given module inside the given file.
# @DEBUG: Enum type like will be added although they must be imported by a syntak like so MyType(..)
#
# Usage: ./debugit.sh FILENAME
#
if [ "$1" == "-d" -o -z "$1" ]; then
node_modules/.bin/elm make src/Main.elm --output=/dev/null
elif [ ! -f $1 ]; then
echo "Error: file unknwown"
exit
fi
PATTERN='cannot find a `.*`'
TARGET="$1"
MODULE="ModelSchema"
TERMS=$(node_modules/.bin/elm make src/Main.elm --output=/dev/null 2>&1 | command grep "$PATTERN" | sed 's/.*`\([^`]*\)`.*/\1/' | sort | uniq | paste -sd "," | sed "s/,/, /g")
if [ -z "$TERMS" ]; then
echo "No terms matched"
exit
fi
grep -q "^import ${MODULE}$" "$TARGET"
if [ $? -eq 0 ]; then
sed -i "s/^import $MODULE$/import $MODULE exposing ($TERMS)/" "$TARGET"
else
sed -i "s/^import $MODULE exposing (\(.*\))$/import $MODULE exposing (\1, $TERMS)/" "$TARGET"
fi