22# @description The Commando.io command-line interface.
33#
44# Commando.io
5- # Copyright 2017 NodeSocket, LLC.
5+ # Copyright 2018 NodeSocket, LLC.
66# All rights reserved.
77
88set -eo pipefail; [[ $TRACE ]] && set -x
99
10- VERSION=" 1.31 "
10+ VERSION=" 1.4 "
1111
1212COMMAND=$1
1313NETRC=~ /.netrc
2121function check_auth {
2222 if [ ! -e $NETRC ] || ! grep -Fxq " machine $API_ENDPOINT " $NETRC ; then
2323 printf " You are not authenticated. To authenticate, run:\n\n\tcommando auth"
24- exit 1
24+ exit 4
2525 fi
2626}
2727
@@ -31,9 +31,9 @@ function curl_request() {
3131 CURL_VERSION=$( curl --version | sed -n 1p)
3232
3333 if [ " $2 " != " " ]; then
34- curl --silent --netrc --user-agent " Commando-Cli/$VERSION $USER $CURL_VERSION " " https://$API_ENDPOINT /v1/$1 " -X POST --data " $2 "
34+ curl --silent --netrc --user-agent --location " Commando-Cli/$VERSION $CURL_VERSION " " https://$API_ENDPOINT /v1/$1 " -X POST --data " $2 "
3535 else
36- curl --silent --netrc --user-agent " Commando-Cli/$VERSION $USER $CURL_VERSION " " https://$API_ENDPOINT /v1/$1 "
36+ curl --silent --netrc --user-agent --location " Commando-Cli/$VERSION $CURL_VERSION " " https://$API_ENDPOINT /v1/$1 "
3737 fi
3838}
3939
@@ -43,7 +43,7 @@ case "$COMMAND" in
4343 if [ -e $NETRC ] && grep -Fxq " machine $API_ENDPOINT " $NETRC ; then
4444 ACCOUNT_ALIAS=$( awk ' /$API_ENDPOINT/{getline; print $2}' $NETRC )
4545 printf " You are already authenticated. To unauthenticate, run:\n\n\tcommando unauth"
46- exit 1
46+ exit 4
4747 fi
4848
4949 read -r -p " Enter your account alias: " ACCOUNT_ALIAS
117117
118118 if [ " $RECIPE_ID " == " " ]; then
119119 printf " Missing required argument recipe id.\n\nUsage:\n\tcommando execute <recipe-id> (--server=<server-id> | --groups=<group-id>,<group-id>,...)"
120- exit 1
120+ exit 4
121121 fi
122122
123123 check_auth
144144 curl_request " recipes/$RECIPE_ID /execute" " groups[]=$GROUP "
145145 else
146146 printf " Missing or invalid option.\n\nUsage:\n\tcommando execute <recipe-id> (--server=<server-id> | --groups=<group-id>,<group-id>,...)"
147- exit 1
147+ exit 4
148148 fi
149149
150150 ;;
155155
156156 if [ " $EXECUTION_QUEUE_ID " == " " ]; then
157157 printf " Missing required argument execution queue id.\n\nUsage:\n\tcommando execution-queue <execution-queue-id>"
158- exit 1
158+ exit 4
159159 fi
160160
161161 check_auth
170170
171171 if [ " $EXECUTION_ID " == " " ]; then
172172 printf " Missing required argument execution id.\n\nUsage:\n\tcommando executions <execution-id>"
173- exit 1
173+ exit 4
174174 fi
175175
176176 check_auth
188188 * )
189189
190190 printf " Usage:\n\tcommando auth\n\tcommando unauth\n\tcommando servers [<server-id>]\n\tcommando groups [<group-id>]\n\tcommando recipes [<recipe-id>]\n\tcommando execute <recipe-id> (--server=<server-id> | --groups=<group-id>,<group-id>,...)\n\tcommando execution-queue <execution-queue-id>\n\tcommando executions <execution-id>\n\tcommando (version | --version)\n\tcommando (help | --help)"
191- exit 1
191+
192+ if [ " $COMMAND " != " help" ] && [ " $COMMAND " != " --help" ]; then
193+ exit 4
194+ fi
195+
192196 ;;
193197
194198esac
0 commit comments