aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-10-21 14:53:03 -0300
committerEuAndreh <eu@euandre.org>2022-10-21 14:53:03 -0300
commite265e9ca31615589ad5020be7595f7ca578987ba (patch)
treee18c60936dee5e7a218c19019ba2bbf14462d843
parentbin/repos: Add new working utility (diff)
downloaddotfiles-e265e9ca31615589ad5020be7595f7ca578987ba.tar.gz
dotfiles-e265e9ca31615589ad5020be7595f7ca578987ba.tar.xz
bin/vcs: Add initial version of VCS compatibility utility
-rwxr-xr-xbin/vcs96
1 files changed, 96 insertions, 0 deletions
diff --git a/bin/vcs b/bin/vcs
new file mode 100755
index 0000000..3cd8ed0
--- /dev/null
+++ b/bin/vcs
@@ -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"