aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2019-06-03 20:29:21 +0200
committerTeddy Wing2019-06-03 20:29:21 +0200
commit66ede8f5d6be6797e19adc712111d118c77accb1 (patch)
tree1287edd4fa9cb776f437f68691c304b69bf8fb52
parent256a25b331c7b95e0a1613b09ba6a2f15fd250fe (diff)
downloadcode-review-66ede8f5d6be6797e19adc712111d118c77accb1.tar.bz2
Add `code-review`, subcommand runner
This script takes a subcommand as the first argument and executes an executable called "code-review-${subcommand}", similar to the way Git does subcommands. Using this subcommand system, I can have different unrelated subcommands in separate files/scripts, making it easier to organise the code.
-rwxr-xr-xcode-review26
1 files changed, 26 insertions, 0 deletions
diff --git a/code-review b/code-review
new file mode 100755
index 0000000..7d92e0f
--- /dev/null
+++ b/code-review
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+EX_USAGE=64
+
+
+function program_exists () {
+ local program="$1"
+
+ command -v "$program" > /dev/null
+}
+
+
+program="code-review"
+subcommand="$1"
+
+if [ -z "$subcommand" ]; then
+ echo 'TODO: print usage'
+ exit "$EX_USAGE"
+fi
+
+if ! program_exists "${program}-${subcommand}"; then
+ echo >&2 "${program}: '${subcommand}' is not a ${program} command. See '${program} --help'"
+ exit "$EX_USAGE"
+fi
+
+eval "${program}-${subcommand}"