Skip to content

Commit

Permalink
Isolated init check to init function
Browse files Browse the repository at this point in the history
  • Loading branch information
rockymadden committed Jul 4, 2016
1 parent 010ff40 commit 3f07da5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/circleci
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

bindir=
etcdir=
_token=$(test -f "${etcdir}/circleci" && sed -n '1p' < "${etcdir}/circleci")
token=${_token}
token=$(test -f "${etcdir}/circleci" && sed -n '1p' < "${etcdir}/circleci")

## Command parsing ################################################################################
cmd="${1}" ; shift
Expand Down Expand Up @@ -104,6 +103,8 @@ esac
## Argument and option prompting ##################################################################
case "${cmd}" in
init)
_token=$(test -f "${etcdir}/circleci" && sed -n '1p' < "${etcdir}/circleci")

if test -z "${token}" || test "${token}" == "${_token}"; then
read -e -p 'Enter CircleCI API token: ' token
fi
Expand Down Expand Up @@ -324,7 +325,8 @@ case "${cmd}" in
artifacts|await|browse|build|builds|cancel|me|notify|project|projects|retry|trigger)
if test -z "${token}"; then
echo '{"initialized": false, "outcome": "failed"}' |
jq -r ${compact} ${monochrome} "${filter:=.}" ; exit 1
jq -r ${compact} ${monochrome} "${filter:=.}"
exit 1
else
"${cmd}" ; exit $?
fi
Expand Down

0 comments on commit 3f07da5

Please sign in to comment.