Force regexp in IOCCC_status_version

As it seems like the version should be a specific format both for
consistency and to keep track of it I added a regexp check in the
ioccc_status.sh script I wrote the other day that does this.

The version must follow the regexp that was devised from the current
IOCCC_status_version of '0.2 2023-05-22' as:

    [0-9]+\.[0-9]+ [0-9]{4}-[0-9]{2}-[0-9]{2}

The usage string has had this added and a new check was added to verify
that the '-i version' matches this format.

This update also will prevent sed from reporting an error if the
separator character (which I originally chose as '/' and then changed it
to '|' but which now could be either or ',' or something else) is in the
version as the version won't have that character.

The format of the version can certainly be changed but this seems like a
worthy idea, to check that there is a required format.

With this the script should be finished though of course something might
be found later on.
This commit is contained in:
Cody Boone Ferguson committed 2023-10-04 02:44:29 -07:00
1 parent 5f92b3d5ad
commit 2e5cd0f16b
1 file changed
+14 -3
+14 -3
View File
@@ -26,7 +26,7 @@
# If the -I status_ver option is used the IOCCC_status_version field will be
# updated.
#
export IOCCC_STATUS_VERSION="0.0.1-0 2023-10-02" # major.minor.release-patch YYYY-MM-DD
export IOCCC_STATUS_VERSION="0.0.2-0 2023-10-04" # major.minor.release-patch YYYY-MM-DD
USAGE="usage: $(basename "$0") [-h] [-V] [-v level] [-s status] [-d] [-n] [-i status_ver] status.json
@@ -41,6 +41,8 @@ USAGE="usage: $(basename "$0") [-h] [-V] [-v level] [-s status] [-d] [-n] [-i st
-n update latest_news date
-i status_ver update IOCCC_status_version
NOTE: version must match the regexp: [0-9]+\.[0-9]+ [0-9]{4}-[0-9]{2}-[0-9]{2}
status.json the file to update
status version: $IOCCC_STATUS_VERSION"
@@ -120,11 +122,20 @@ if [[ ! -r $STATUS_JSON_FILE ]]; then
exit 1
fi
# check that if -s used that the status ($STATUS) is either 'open' or 'closed'
# check that if -s ($STATUS_FLAG) used that the status ($STATUS) is either 'open' or 'closed'
if [[ -n "$STATUS_FLAG" ]]; then
if [[ "$STATUS" != "open" && "$STATUS" != "closed" ]]; then
echo "$0: ERROR: status must be 'open' or 'closed'" 1>&2
exit 1
exit 3
fi
fi
# check format of IOCCC_status_version if set (-i used, $UPDATE_IOCCC_STATUS_VERSION)
if [[ -n "$UPDATE_IOCCC_STATUS_VERSION" ]]; then
echo "$IOCCC_STATUS_VERSION" | grep -qE '[0-9]+\.[0-9]+ [0-9]{4}-[0-9]{2}-[0-9]{2}'
if [[ "${PIPESTATUS[1]}" -ne 0 ]]; then
echo "$0: ERROR: IOCCC_status_version must match the regexp: '[0-9]+\.[0-9]+ [0-9]{4}-[0-9]{2}-[0-9]{2}'" 1>&2
exit 3
fi
fi