Script 'game-add': add usage and version outputs.
This commit is contained in:
parent
b5223800e4
commit
153defb1ba
50
game-add
50
game-add
@ -8,6 +8,35 @@ TOURNAMENT="2014/2-summertime"
|
|||||||
# Config file for players
|
# Config file for players
|
||||||
ply_ini="${REPODIR}/${TOURNAMENT}/players.ini"
|
ply_ini="${REPODIR}/${TOURNAMENT}/players.ini"
|
||||||
|
|
||||||
|
# Version information
|
||||||
|
VERSION="0.1"
|
||||||
|
|
||||||
|
argv0="${0##*/}"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<EOF
|
||||||
|
Store a chess game played on lichess.org
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
$argv0 -t <num> <url>
|
||||||
|
$argv0 -h
|
||||||
|
$argv0 -v
|
||||||
|
|
||||||
|
The first form fills the result of a chess game and stores its PGN
|
||||||
|
file. Assumes that the game is available at <url> (lichess.org) and
|
||||||
|
corresponds to tournament tour <num>.
|
||||||
|
|
||||||
|
The second form shows this help output. The third form shows version
|
||||||
|
information.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
exit "${1:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
version() {
|
||||||
|
exec echo "${argv0}-${VERSION}"
|
||||||
|
}
|
||||||
|
|
||||||
game_get_players() {
|
game_get_players() {
|
||||||
# Extract players on Lichess
|
# Extract players on Lichess
|
||||||
local w_lichess=$(sed -En "s/\[White \"([^\"]*)\"\]/\1/p" < "$tmp_pgn")
|
local w_lichess=$(sed -En "s/\[White \"([^\"]*)\"\]/\1/p" < "$tmp_pgn")
|
||||||
@ -124,30 +153,25 @@ die() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkargs() {
|
checkargs() {
|
||||||
if [[ "$opt" == t && ! "$OPTARG" =~ ^[0-9]+$ ]]; then
|
if [[ "$opt" == t && "$OPTARG" =~ ^[0-9]+$ ]]; then
|
||||||
echo "Incorrect tour number" 1>&2
|
TOUR=$(printf "%02g" "$OPTARG")
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
TOUR=""
|
TOUR=""
|
||||||
|
|
||||||
while getopts "t:hv" opt; do
|
while getopts "t:hv" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
t) checkargs
|
t) checkargs ;;
|
||||||
TOUR=$(printf "%02g" "$OPTARG")
|
h) usage ;;
|
||||||
;;
|
v) version ;;
|
||||||
h) usage && exit 0
|
*) usage 1 ;;
|
||||||
;;
|
|
||||||
v) version && exit 0
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
shift $(($OPTIND - 1))
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
# For now, tour number should be given explicitly
|
# For now, tour number should be given explicitly
|
||||||
[[ -z "$TOUR" ]] && die "Tour number not specified."
|
[[ -z "$TOUR" || -z "$1" ]] && usage 1
|
||||||
|
|
||||||
tour_info="${REPODIR}/${TOURNAMENT}/tours/${TOUR}/tour_info"
|
tour_info="${REPODIR}/${TOURNAMENT}/tours/${TOUR}/tour_info"
|
||||||
[[ ! -f "$tour_info" ]] && die "File ${tour_info} not found."
|
[[ ! -f "$tour_info" ]] && die "File ${tour_info} not found."
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user