Skip to content

Commit

Permalink
fix(github): Update github-auth with interactive and reset options
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed May 27, 2023
1 parent 8d99e6b commit 7afd910
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions chezmoi/dot_local/bin/executable_github-auth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@
# {{ template "scripts-library" }}
log_task "Authenticating with GitHub"

# check if --interactive or -f flag is set
set +u
if [[ "${1}" == "--interactive" ]] || [[ "${1}" == "-i" ]]; then
INTERACTIVE=true
else
INTERACTIVE=false
fi
set -u
INTERACTIVE=false
RESET=false

usage() {
echo "Usage: $0 [-i|--interactive] [-r|--reset] [-h|--help]"
echo
echo "Options:"
echo " -i, --interactive Enable interactive mode."
echo " -r, --reset Enable reset mode."
echo " -h, --help Display this help message."
exit 1
}

while (( "$#" )); do
case "$1" in
--interactive|-i)
INTERACTIVE=true
shift
;;
--reset|-r)
RESET=true
shift
;;
--help|-h)
usage
;;
*)
echo "Error: Invalid argument"
usage
esac
done

GITHUB_USERNAME=${GITHUB_USERNAME:-"{{ .github.username }}"}
GITHUB_TOKEN=${GITHUB_TOKEN:-"{{ .github.token }}"}
Expand All @@ -23,6 +46,12 @@ if ! command -v gh >/dev/null; then
exit 0
fi

if [[ "${RESET}" == "true" ]]; then
log_info "Resetting GitHub authentication"
export GITHUB_TOKEN=""
export GH_TOKEN=""
fi

c gh config set -h github.com git_protocol https
if [[ "${INTERACTIVE}" == "true" ]]; then
log_info "Logging in to GitHub"
Expand Down

0 comments on commit 7afd910

Please sign in to comment.