From 7afd910b04fa3709f2aeb384177aceb03ad50f7e Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Sat, 27 May 2023 20:23:19 +0900 Subject: [PATCH] fix(github): Update github-auth with interactive and reset options --- .../dot_local/bin/executable_github-auth.tmpl | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/chezmoi/dot_local/bin/executable_github-auth.tmpl b/chezmoi/dot_local/bin/executable_github-auth.tmpl index 42024fc7..f9b07b0d 100644 --- a/chezmoi/dot_local/bin/executable_github-auth.tmpl +++ b/chezmoi/dot_local/bin/executable_github-auth.tmpl @@ -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 }}"} @@ -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"