commit 10ae4f111d5b6a2af2cfe2e13527f00972a8474b
Author: david.sorber <david.sorber@jacobs.com>
Date:   Fri Mar 22 15:06:19 2024 -0400

    Add the ability to specify the input file path as a command line argument. Bumping to v0.1.4.

diff --git a/src/main.cc b/src/main.cc
index 9de9a72..f885373 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -7,14 +7,14 @@
 // Important to understand: SDL_Renderer is an _optional_ component of SDL2.
 // For a multi-platform app consider using e.g. SDL+DirectX on Windows and
 // SDL+OpenGL on Linux/OSX.
-
+#include <algorithm>
 #include <cstdio>
 #include <cstdint>
 #include <cstring>
+#include <filesystem>
 #include <iostream>
-#include <map>
 #include <string>
-#include <vector>
+#include <string_view>
 
 #include <SDL.h>
 
@@ -26,12 +26,14 @@
 #include "RobotoMedium.h"
 
 
+namespace sfs = std::filesystem;
+
 #if !SDL_VERSION_ATLEAST(2,0,17)
 #error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
 #endif
 
 const std::string APP_NAME("pwmgr");
-const std::string VERSION("v0.1.3");
+const std::string VERSION("v0.1.4");
 const std::string DEFAULT_FILEPATH("/home/dsorber/Documents/chicken_soup/chicken_soup.txt.enc");
 
 const std::string BOLD{"\033[1m"};
@@ -52,6 +54,7 @@ Catalog catalog;
 const char* STR_EMPTY = "";
 const char* STR_PWD = "enter password and click \"Load\"";
 const char* STR_LOADING = "Loading...";
+const char* STR_BAD_FILE = "specified input file does not exist";
 
 static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS =
         ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_ReadOnly;
@@ -178,7 +181,20 @@ int main(int argc, char** argv)
     bool loading = false;
     char filterBuffer[128]{};
     char filePathBuffer[BUFFER_SIZE]{};
-    std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(), DEFAULT_FILEPATH.size());
+    if (argc == 2)
+    {
+        // Use command line specified file path
+        std::string_view cmdLineFilePath(argv[1]);
+        size_t copySize = std::min(BUFFER_SIZE,
+                                   static_cast<uint32_t>(cmdLineFilePath.size()));
+        std::memcpy(filePathBuffer, argv[1], copySize);
+    }
+    else
+    {
+        // Use default file path
+        std::memcpy(filePathBuffer, DEFAULT_FILEPATH.data(),
+                    DEFAULT_FILEPATH.size());
+    }
     const char* statusText = STR_PWD;
 
     char passwdBuffer[BUFFER_SIZE]{};
@@ -268,8 +284,19 @@ int main(int argc, char** argv)
 
                 if (ImGui::Button("Load"))
                 {
-                    loading = true;
-                    statusText = STR_LOADING;
+                    if (sfs::exists(filePathBuffer))
+                    {
+                        loading = true;
+                        statusText = STR_LOADING;
+                    }
+                    else
+                    {
+                        statusText = STR_BAD_FILE;
+                        //TODO:
+                        std::cerr << ERROR_MSG << "Input file: \""
+                                  << filePathBuffer << "\" does not exist!"
+                                  << std::endl;
+                    }
                 }
                 ImGui::SameLine();
 
@@ -350,7 +377,7 @@ int main(int argc, char** argv)
                                     iter.getValueBuffer(),
                                     iter.getValueBufferSize(),
                                     ImVec2(-FLT_MIN,
-                                               ImGui::GetTextLineHeight() * 5),
+                                             ImGui::GetTextLineHeight() * 5),
                                     MULTILINE_TEXT_FLAGS);
                         }
                     }
