refactor: Use same setup as rbenv-init for reading arguments in

pyenv-init.

- It turns out that the code I wrote was very similar to what was
  already present in rbenv-init.

As rbenv is referenced when I am writing a pull request, I am assuming
that maintainers want code similar to what's already there.

WARNING:
The code will now not validate whether the specified shell is valid or
not, and if you make a silly mistake like writing `--parh` instead of
`--path`, the shell may be set to `--parh` and so forth. But I guess
this is acceptable.
This commit is contained in:
Christian Fredrik Johnsen 2024-12-11 03:32:02 +01:00
parent b21c209329
commit 198c89471a

View File

@ -24,14 +24,11 @@ no_rehash=""
no_push_path="" no_push_path=""
shell="" shell=""
for arg in "$@"; do while [ "$#" -gt 0 ]; do
case "$arg" in case "$1" in
-) -)
mode="print" mode="print"
;; ;;
zsh|bash|ksh|fish)
shell="$arg"
;;
--path) --path)
mode="path" mode="path"
;; ;;
@ -45,11 +42,10 @@ for arg in "$@"; do
no_rehash=1 no_rehash=1
;; ;;
*) *)
echo "Warning: Unknown option '$arg'" >&2 shell="$1"
echo "Run 'pyenv init --help' for usage." >&2
exit 1
;; ;;
esac esac
shift
done done
# If shell is not provided, detect it. # If shell is not provided, detect it.