Skip to content

Commit

Permalink
chore: pg-pitr supports argument style "--<method>=<value>"
Browse files Browse the repository at this point in the history
example: `pg-pitr --backup=20221108-105325`
  • Loading branch information
waitingsong committed Dec 9, 2024
1 parent f7704c8 commit 583da86
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions files/postgres/pg-pitr
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ function is_valid_ip(){
return 1
fi
}
function assign() {
if [[ $1 == *=* ]]; then # --backup=foo
TARGET="${1#*=}"
else # --backup foo / -b foo
TARGET=$2
shift
fi
}
#--------------------------------------------------------------#
Expand All @@ -114,11 +122,26 @@ while [ $# -gt 0 ]; do
-s|--stanza) STANZA=$2 ; shift ;;
-d|--default) METHOD="default" ; ;;
-i|--immediate) [[ ${METHOD} != "default" ]] && usage ; METHOD="immediate" ; ;;
-t|--time) [[ ${METHOD} != "default" ]] && usage ; METHOD="time" ; TARGET=$2; shift;;
-n|--name) [[ ${METHOD} != "default" ]] && usage ; METHOD="name" ; TARGET=$2; shift;;
-b|--backup) [[ ${METHOD} != "default" ]] && usage ; METHOD="set" ; TARGET=$2; shift;;
-l|--lsn) [[ ${METHOD} != "default" ]] && usage ; METHOD="lsn" ; TARGET=$2; shift;;
-x|--xid) [[ ${METHOD} != "default" ]] && usage ; METHOD="xid" ; TARGET=$2; shift;;
-t|--time*)
[[ ${METHOD} != "default" ]] && usage ;
METHOD="time"; assign $1 "${2:-}"
[[ $1 != *=* ]] && shift ;;
-n|--name*)
[[ ${METHOD} != "default" ]] && usage ;
METHOD="name"; assign $1 "${2:-}"
[[ $1 != *=* ]] && shift ;;
-b|--backup*)
[[ ${METHOD} != "default" ]] && usage;
METHOD="set"; assign $1 "${2:-}"
[[ $1 != *=* ]] && shift ;;
-l|--lsn*)
[[ ${METHOD} != "default" ]] && usage ;
METHOD="lsn"; assign $1 "${2:-}"
[[ $1 != *=* ]] && shift ;;
-x|--xid*)
[[ ${METHOD} != "default" ]] && usage ;
METHOD="xid"; assign $1 "${2:-}"
[[ $1 != *=* ]] && shift ;;
-X|--target-exclusive) TARGET_EXCLUSIVE=true ;;
-P|--target-action) TARGET_ACTION="promote" ;;
(--) shift; break;;
Expand Down

0 comments on commit 583da86

Please sign in to comment.