From 76db00fbe037967285ec7add2c67a4e8ea7d6f15 Mon Sep 17 00:00:00 2001
From: Sebastien Masson <sebastien.masson@locean.ipsl.fr>
Date: Wed, 28 Sep 2022 17:14:54 +0200
Subject: [PATCH] improve the robustness of -n/r/a options in makenemo, #68

---
 makenemo       | 20 ++++++++++++++++----
 sette/sette.sh |  2 +-
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/makenemo b/makenemo
index 7b20c3c31..8f429bd2d 100755
--- a/makenemo
+++ b/makenemo
@@ -223,11 +223,23 @@ done
 
 if [ -n "$x_name" ]   # is the configuration existing in cfgs or tests? or is it a new conf?
 then
-    incfg=$( find $CFGS_DIR -type d -name $x_name | wc -l )   # this configuration exists in CFGS_DIR
+    incfg=$( find $CFGS_DIR   -type d -name $x_name | wc -l )   # this configuration exists in CFGS_DIR
     intst=$( find $TESTS_DIR  -type d -name $x_name | wc -l )   # this configuration exists in TESTS_DIR
-    [[ $incfg -eq 0 && $intst -eq 0 ]] && x_n=$x_name   # this is a new configuration       -> dedine/overwrite x_n
-    [[ $incfg -eq 1 &&    -z "$x_r" ]] && x_r=$x_name   # this is a reference configuration -> dedine/overwrite x_r
-    [[ $intst -eq 1 &&    -z "$x_a" ]] && x_a=$x_name   # this is a test configuration      -> dedine/overwrite x_a
+    if [ $(( $incfg + $intst )) -eq 2 ] ; then
+	echo -e "\033[0;31m\nERROR: the $x_name directory is found twice: in $CFGS_DIR and in $TESTS_DIR\033[0m\n"
+	exit 4
+    fi
+    if [ $(( $incfg + $intst )) -gt 0 ] ; then
+	[ -n "$x_r" ] && echo -e "\nWARNING: $x_name configuration is already existing, we ignore \"-r $x_r\"\n"
+	[ -n "$x_a" ] && echo -e "\nWARNING: $x_name configuration is already existing, we ignore \"-a $x_a\"\n"
+    fi
+    if   [ $incfg -eq 1 ] ; then
+	x_r=$x_name ; x_a=''  # reference configuration existing -> define/overwrite x_r
+    elif [ $intst -eq 1 ] ; then
+	x_a=$x_name ; x_r=''   # test      configuration existing -> define/overwrite x_a
+    else
+	x_n=$x_name            # this is a new configuration      -> define
+    fi
 fi
 
 export NEW_CONF=${x_n}
diff --git a/sette/sette.sh b/sette/sette.sh
index 9c3e0a3a2..7537af5e8 100755
--- a/sette/sette.sh
+++ b/sette/sette.sh
@@ -166,7 +166,7 @@ if [ $# -gt 0 ]; then
                echo '                  for SETTE-built configurations (needed if sette.sh invocations may overlap)'
                echo '-r to execute without waiting to run sette_rpt.sh at the end (useful for chaining sette.sh invocations)'
                echo '-y to perform a dryrun to simply report what settings will be used'
-               echo '-d to compile Nemo with debug options (only if %DEBUG_FCFLAGS if defined in your arch file)'
+               echo '-b to compile Nemo with debug options (only if %DEBUG_FCFLAGS if defined in your arch file)'
                echo '-c to clean each configuration'
                echo '-s to synchronise the sette MY_SRC and EXP00 with the reference MY_SRC and EXPREF'
                echo '-u to run sette.sh without any user interaction. This means no checks on creating'
-- 
GitLab