diff options
Diffstat (limited to 'bin/vcs')
-rwxr-xr-x | bin/vcs | 96 |
1 files changed, 96 insertions, 0 deletions
@@ -0,0 +1,96 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + vcs TYPE ACTION + vcs -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + TYPE the type of the underlying VCS: + - git + - darcs + - mercurial + - fossil + - cvs + ACTION the action to be performed on the repository: + - fetch + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + esac +done +shift $((OPTIND - 1)) + + +git_fetch() { + git fetch +} + +darcs_fetch() { + darcs fetch +} + +mercurial_fetch() { + hg pull +} + +fossil_fetch() { + fossil pull +} + +cvs_fetch() { + cvs update +} + + +VCS="${1:-}" +ACTION="${2:-}" + +eval "$(assert-arg "$VCS" 'VCS')" +eval "$(assert-arg "$ACTION" 'ACTION')" + + +CMD="$VCS"_"$ACTION" +if ! command -v "$CMD" >/dev/null; then + printf 'Invalid VCS/action combination: %s %s.\n' "$VCS" "$ACTION" >&2 + exit 2 +fi + +"$CMD" |