dam/src/parser

181 lines
4.1 KiB
Text
Raw Normal View History

#!/bin/bash
###
# Parses arguments and commands from shell
###
GIT_DIR="./"
#Recursive argument parser
2018-05-04 10:31:53 -07:00
while true; do
case ${1} in
--help)
shift
HELP="${1}"
[[ -z "${HELP}" ]] && HELP=general
eval help_${HELP}
exit
;;
--info)
help_info
exit
;;
--git-dir)
shift
GIT_DIR="${1}"
;;
*)
break
;;
esac
shift
done
case "${1}" in
2018-05-16 00:03:13 -07:00
init)
shift
cmd_init "${GIT_DIR}" ${@}
EXIT=$?
[[ ${EXIT} -eq 1 ]] && echo "Database file already present"
[[ ${EXIT} -eq 2 ]] && echo "Init had errors"
;;
import)
shift
case "${1}" in
tracks)
shift
cmd_import_tracks "${GIT_DIR}" ${@}
;;
images)
shift
cmd_import_images "${GIT_DIR}" ${@}
;;
*)
echo "${1} not a valid command"
;;
esac
;;
exclude)
shift
cmd_exclude "${GIT_DIR}" ${@}
EXIT=$?
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
include)
shift
cmd_include "${GIT_DIR}" ${@}
EXIT=$?
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
export)
shift
while [[ -n "${1}" ]]; do
case ${1} in
--from)
shift
OLD_COMMIT=${1}
shift
;;
*)
TARGET="${1}"
shift
;;
esac
done
cmd_export "${GIT_DIR}" "${TARGET}" "${OLD_COMMIT}"
EXIT=$?
[[ ${EXIT} -eq 0 ]] && echo "Deployment completed successfully"
2018-04-15 21:30:01 -04:00
[[ ${EXIT} -eq 1 ]] && echo "Deployment completed with errors"
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
update)
shift
while [[ -n "${1}" ]]; do
case ${1} in
--from)
shift
OLD_COMMIT=${1}
shift
;;
*)
TARGET="${1}"
shift
;;
esac
done
2018-04-15 23:05:39 -04:00
cmd_update "${GIT_DIR}" "${TARGET}" "${OLD_COMMIT}"
EXIT=$?
[[ ${EXIT} -eq 0 ]] && echo "Update completed successfully"
2018-04-15 21:30:01 -04:00
[[ ${EXIT} -eq 1 ]] && echo "Update completed with errors"
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
du)
shift
cmd_du "${GIT_DIR}" "${@}"
EXIT=$?
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
fsck)
shift
2018-04-15 22:33:45 -04:00
while [[ -n "${1}" ]]; do
case ${1} in
--nonexistent-ids)
cmdList=(${cmdList[@]} nonexistent-ids)
shift
;;
--deployed-ids)
cmdList=(${cmdList[@]} deployed-ids)
shift
;;
--metadata)
cmdList=(${cmdList[@]} metadata)
shift
;;
*)
TARGET="${1}"
shift
;;
esac
done
[[ -z ${cmdList[@]} ]] && cmdList=(deployed-ids nonexistent-ids metadata)
cmd_fsck "${GIT_DIR}" "${TARGET}" ${cmdList[@]}
EXIT=$?
[[ ${EXIT} -eq 3 ]] && echo "Database file non-existent"
[[ ${EXIT} -eq 2 ]] && echo "Git directory not a valid git repository"
;;
*)
help_general
;;
esac