dotfiles/dot_config/fish/private_functions/private_kdjango.fish

30 lines
1.2 KiB
Fish
Raw Normal View History

2021-08-10 10:50:48 +02:00
# Defined interactively
function kdjango --description 'Pop into the shell of django pod of the current namespace'
2022-03-23 16:04:35 +01:00
argparse -x "h,b,s,m,o,d" "h/help" "b/bash" "s/sh" "m/manage" "o/original-shell" "d/db-shell" -- $argv; or return
2021-08-10 10:50:48 +02:00
if set -q _flag_h
echo "Exec into the django pod of the current namespace..."
echo -e "kdjango [-b]\t ...using bash (default if no option)"
echo -e "kdjango -s\t ...using sh"
2022-03-21 14:06:28 +01:00
echo -e "kdjango -m\t ...using manage.py shell_plus"
echo -e "kdjango -o\t ...using manage.py shell"
2022-03-23 16:04:35 +01:00
echo -e "kdjango -d\t ...using manage.py dbshell"
2021-08-10 10:50:48 +02:00
echo -e "\nRequires kubens for namespace selection"
return
end
set -l command /bin/bash
if set -q _flag_b
set command /bin/bash
else if set -q _flag_s
set command /bin/sh
else if set -q _flag_m
2022-03-21 14:06:28 +01:00
set command ./manage.py shell_plus
else if set -q _flag_o
2021-08-10 10:50:48 +02:00
set command ./manage.py shell
2022-03-23 16:04:35 +01:00
else if set -q _flag_d
set command ./manage.py dbshell
2021-08-10 10:50:48 +02:00
end
set pod (kubectl get pods -o name | grep "django" | grep -Ev "celery|migrations" | head -1)
echo "running $command in $pod"
kubectl exec -it $pod -- $command
end