summaryrefslogtreecommitdiff
path: root/scripts/generate-const.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/generate-const.sh')
-rwxr-xr-xscripts/generate-const.sh11
1 files changed, 11 insertions, 0 deletions
diff --git a/scripts/generate-const.sh b/scripts/generate-const.sh
new file mode 100755
index 0000000..f049389
--- /dev/null
+++ b/scripts/generate-const.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+#
+# Generates a Go const from the contents of a static file, and appends it at
+# the line following the go:generate directive that calls this script.
+#
+set -euo pipefail
+
+sed -i.sed.bak -e "$((GOLINE+1)),\$d" "$GOFILE"
+rm "$GOFILE.sed.bak"
+
+(echo -n "const $1 = \`"; cat "$2"; echo "\`") >> "$GOFILE"