Cleaner way to handle special actions 'help' and 'version'

This commit is contained in:
Tortue Torche 2019-08-10 22:13:34 -04:00 committed by Tortue Torche
parent 3b6a8bf7e6
commit 7f94f8b5da

8
psu Executable file → Normal file
View File

@ -30,7 +30,6 @@ main() {
set_globals "$@"
if [ "$ACTION" != "help" ] && [ "$ACTION" != "version" ]; then
# Get Portainer auth token. Will be used on every API request.
echo_verbose "Getting auth token..."
AUTH_TOKEN=$(http \
@ -60,7 +59,6 @@ main() {
STACK=$(echo "$STACKS" \
| jq --arg PORTAINER_STACK_NAME "$PORTAINER_STACK_NAME" -jc '.[] | select(.Name == $PORTAINER_STACK_NAME)')
echo_debug "Stack ${PORTAINER_STACK_NAME} -> $(echo $STACK | jq -C .)"
fi
if [ $ACTION == "deploy" ]; then
deploy
@ -273,11 +271,9 @@ set_globals() {
# Check required arguments have been provided
check_argument "$ACTION" "action" "ACTION" "a" "action"
if [ "$ACTION" != "help" ] && [ "$ACTION" != "version" ]; then
check_argument "$PORTAINER_USER" "portainer user" "PORTAINER_USER" "u" "user"
check_argument "$PORTAINER_PASSWORD" "portainer password" "PORTAINER_PASSWORD" "p" "password"
check_argument "$PORTAINER_URL" "portainer url" "PORTAINER_URL" "l" "url"
fi
if [ "$ACTION" == "deploy" ]; then
check_argument "$DOCKER_COMPOSE_FILE" "docker compose file" "DOCKER_COMPOSE_FILE" "c" "compose-file"
if [ -n "$ENVIRONMENT_VARIABLES_FILE" ] && [[ ! -f "$ENVIRONMENT_VARIABLES_FILE" ]]; then
@ -285,7 +281,7 @@ set_globals() {
exit 1
fi
fi
if [ "$ACTION" != "list" ] && [ "$ACTION" != "help" ] && [ "$ACTION" != "version" ]; then
if [ "$ACTION" != "list" ]; then
check_argument "$PORTAINER_STACK_NAME" "portainer stack name" "PORTAINER_STACK_NAME" "n" "name"
fi
}
@ -436,6 +432,7 @@ inputs() {
if [ -n "$version_message" ]; then
ACTION="version"
echo "$version_message"
exit 0
fi
;;
-h|--help|help)
@ -490,6 +487,7 @@ inputs() {
exit 1
fi
fi
exit 0
;;
-a=*|--action=*|-a|--action)
# DEPRECATED: To keep backwards compatibility with psu 0.1.x