From 66ede8f5d6be6797e19adc712111d118c77accb1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 3 Jun 2019 20:29:21 +0200 Subject: 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. --- code-review | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 code-review 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}" -- cgit v1.2.3