diff --git a/bin/git-synk b/bin/git-synk index 59d33f60..afadb808 100755 --- a/bin/git-synk +++ b/bin/git-synk @@ -4,13 +4,12 @@ # Synchronise a local git repository with remote # +import argparse import datetime import os import re from subprocess import call, getoutput, STDOUT -fetch_window = 600 - def is_git_repo(path): return os.path.isdir(path) and ( @@ -44,7 +43,7 @@ def printf(message): print(message, end="") -def synk(path): +def synk(path, fetch_window: int): if not is_git_repo(path): raise Exception( f"Directory {path} is not a git repository and can not be synked" @@ -116,18 +115,24 @@ def synk(path): def run(): + parser = argparse.ArgumentParser(description="Git synk") + parser.add_argument("--window", "-w", help="fetch window in seconds", default=600) + args = parser.parse_args() + + fetch_window = int(args.window) + cwd = os.getcwd() match = re.search("projects/things", cwd) if not match: raise Exception("Can only sync in project/things directory") if is_git_repo(cwd): - synk(cwd) + synk(cwd, fetch_window=fetch_window) else: for child in os.listdir(cwd): directory = os.path.join(cwd, child) if is_git_repo(directory): - synk(directory) + synk(directory, fetch_window=fetch_window) run() diff --git a/bin/things-sync b/bin/things-sync index 02ab81a5..17025614 100755 --- a/bin/things-sync +++ b/bin/things-sync @@ -8,11 +8,23 @@ is-connected || (echo "Not connected, no sync" ; exit 1) FETCH_WINDOW=600 EXTRA_ARGS="" -while getopts "cw:" o; do case "$o" in - c) EXTRA_ARGS="-c" ;; +while getopts "chw:" o; do case "$o" in + h) HELP=y ;; w) FETCH_WINDOW=$OPTARG ;; esac done +help() { + cat << EOF + -h this help + -w 600 set fetch window in seconds +EOF +} + +if [ "$HELP" == "y" ] ; then + help + exit 1 +fi + cd $THINGS_DIR git synk -w $FETCH_WINDOW $EXTRA_ARGS