#!/usr/bin/env bash
# Copyright (c) 2019 Teddy Wing
#
# This file is part of Code Review.
#
# Code Review is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Code Review is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Code Review. If not, see .
EX_USAGE=64
VERSION=0.0.1
function print_usage () {
cat <<-EOF
usage: code-review [--help] [--version] []
Commands:
changed-files List names of files changed
commits One-line log of commits
diff Unified diff of changes
difftool Diff of all changes with Vim and Fugitive
start Start a review with a given base revision
stat Stat file changes
EOF
}
function program_exists () {
local program="$1"
command -v "$program" > /dev/null
}
program="code-review"
subcommand="$1"
if [ -z "$subcommand" ] || [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
print_usage
exit "$EX_USAGE"
fi
if [ "$1" = '--version' ]; then
echo "$VERSION"
exit 0
fi
if ! program_exists "${program}-${subcommand}"; then
echo >&2 "${program}: '${subcommand}' is not a ${program} command. See '${program} --help'"
exit "$EX_USAGE"
fi
shift
eval "${program}-${subcommand}" "$@"