From fd96b046eaa35da0dff7c02b52d0b868a8746dc6 Mon Sep 17 00:00:00 2001
From: Eva Schiffer <evas@ssec.wisc.edu>
Date: Mon, 11 Oct 2021 15:09:42 -0500
Subject: [PATCH] warn the user if we're discarding their command line input in
 favor of a config file

---
 pyglance/glance/config_organizer.py | 33 ++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py
index 0eb529d..9fd082d 100644
--- a/pyglance/glance/config_organizer.py
+++ b/pyglance/glance/config_organizer.py
@@ -321,8 +321,32 @@ def _import_module(full_name, full_file_path,) :
     spec.loader.exec_module(mod)
     return mod
 
-# TODO, right now this is the top level function that the library functions in
-# compare.py call
+# FUTURE, if we update the things that could be stomped from the command line, we have to update this as well, sadly
+# the key here is the option key we expect in the optionSet and the value is the default value
+_STOMPABLE_OPTIONS = {
+                        EPSILON_KEY:                0.0,
+                        OPTIONS_FILL_VALUE_KEY:     None,
+                        OPTIONS_LAT_VAR_NAME_KEY:   'pixel_latitude',
+                        OPTIONS_LON_VAR_NAME_KEY:   'pixel_longitude',
+                        OPTIONS_LONLAT_EPSILON_KEY: 0.0,
+                        OPTIONS_IMAGES_ON_FAIL_KEY: False,
+                        DO_MAKE_FORKS_KEY:          False,
+                     }
+def _warn_for_stomped_commandline_options(optionSet) :
+    """
+    Given the optionSet that the user's input created, warn them if a config file is going to stomp some of these
+    """
+
+    for option_key in sorted(_STOMPABLE_OPTIONS.keys()) :
+        if ( option_key in optionSet and
+             optionSet[option_key] is not None and
+             optionSet[option_key] != _STOMPABLE_OPTIONS[option_key] ) :
+            LOG.warn("User provided input for the option \"" + option_key + "\" on the command line that "
+                     "will be overridden by the requested config file. "
+                     "This part of the command line input will be ignored.")
+            LOG.debug("User value for " + option_key + ": " + str(optionSet[option_key]))
+
+# TODO, right now this is the top level function that the library functions in compare.py call
 def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) :
     """
     load information on how the user wants to run the command from a dictionary of options 
@@ -368,7 +392,10 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) :
         else :
             
             LOG.info ("Using Config File Settings")
-            
+
+            # if the user entered stuff in the command line options that we're going to be ignoring, let's warn them
+            _warn_for_stomped_commandline_options(optionsSet)
+
             # this will handle relative paths
             requestedConfigFile = os.path.abspath(os.path.expanduser(requestedConfigFile))
             
-- 
GitLab