diff options
author | EuAndreh <eu@euandre.org> | 2022-10-21 14:53:03 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-10-21 14:53:03 -0300 |
commit | e265e9ca31615589ad5020be7595f7ca578987ba (patch) | |
tree | e18c60936dee5e7a218c19019ba2bbf14462d843 /bin/vcs | |
parent | bin/repos: Add new working utility (diff) | |
download | dotfiles-e265e9ca31615589ad5020be7595f7ca578987ba.tar.gz dotfiles-e265e9ca31615589ad5020be7595f7ca578987ba.tar.xz |
bin/vcs: Add initial version of VCS compatibility utility
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" |