Skip to content

Commit

Permalink
[#87] Provide support for major-version based config files
Browse files Browse the repository at this point in the history
This commit introduces the possibility to handle per-major-version
configuration files (e.g., `17.conf`) that are loaded in the case the
version specific file (.e.g., `17.1.conf`) is not found on the system.

The loading of a configuration file gives priority to the exact
version, so for instance `17.1.conf`, then if such file is not found
the program tries to load a `17.conf` (i.e., major mode file), and at
last the `default.conf` file.

Bump version to 1.3.9

Close #87
  • Loading branch information
fluca1978 committed Mar 3, 2025
1 parent ad649ca commit 4f77fa9
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# VERSION
#
PGENV_VERSION="1.3.8"
PGENV_VERSION="1.3.9"

# https://stackoverflow.com/a/19622569/79202
trap 'exit' ERR
Expand Down Expand Up @@ -559,21 +559,47 @@ pgenv_configuration_dump_or_exit(){
# will be 'sourced' into the current script runtime.
#
# The function accepts an optional argument which is the version number
# to search for. A configuration file with such version number
# will be used as configuration, and in the case it is missing, the default
# configuration file will be used.
# in the format <major>.<minor>.
# The function searches for files in this order:
# - if a version number has been specified, searches for the <major>.<minor>.conf file
# - if the above is not found, it searches for <major>.conf file
# - if the above is not found or no version has been specified, it searches for the default.conf
# file.
#
# This means that, for instance, specifying the version as 17.2 makes the files to be selected
# in the following order of preference:
# - 17.2.conf
# - 17.conf
# - default.conf
#
# The first file found is used to load the configuration from.
#
# The function sets the PGENV_CONFIGURATION_FILE variable to the name of the
# file loaded or to an empty string. This helps understanding later on
# if the configuration has been loaded.
pgenv_configuration_load(){
local v=$1
local major

# extract the major version of PostgreSQL
if [[ "$v" =~ ^([[:digit:]]+) ]]; then
major="${BASH_REMATCH[1]}"
fi

if [ $major -lt 10 ]; then
# here the major version is made by two numbers, e.g., 9.6
if [[ "$v" =~ ^([[:digit:]].[[:digit:]]) ]]; then
major="${BASH_REMATCH[1]}"
fi
fi


local PGENV_DEFAULT_CONFIG_FILE=$( pgenv_configuration_file_name )
local PGENV_MAJOR_CONFIG_FILE=$( pgenv_configuration_file_name $major )
local PGENV_CONFIG_FILE=$( pgenv_configuration_file_name $v )
PGENV_CONFIGURATION_FILE=''

for conf in $( echo "$PGENV_CONFIG_FILE" "$PGENV_DEFAULT_CONFIG_FILE" )
for conf in $( echo "$PGENV_CONFIG_FILE" "$PGENV_MAJOR_CONFIG_FILE" "$PGENV_DEFAULT_CONFIG_FILE" )
do
pgenv_debug "Looking for configuration in $conf"

Expand Down

0 comments on commit 4f77fa9

Please sign in to comment.