OSDN Git Service

Write an error message to the console when unknown command-line option is specified
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 22 Oct 2018 14:14:23 +0000 (23:14 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Mon, 22 Oct 2018 14:14:23 +0000 (23:14 +0900)
Src/Merge.cpp
Src/MergeCmdLineInfo.cpp
Src/MergeCmdLineInfo.h

index 9d2fc64..60c5814 100644 (file)
@@ -204,6 +204,19 @@ BOOL CMergeApp::InitInstance()
 
        Options::Init(m_pOptions.get()); // Implementation in OptionsInit.cpp
        ApplyCommandLineConfigOptions(cmdInfo);
+       if (cmdInfo.m_sErrorMessages.size() > 0)
+       {
+               if (AttachConsole(static_cast<DWORD>(-1)))
+               {
+                       DWORD dwWritten;
+                       for (auto& msg : cmdInfo.m_sErrorMessages)
+                       {
+                               String line = _T("WinMerge: ") + msg + _T("\n");
+                               WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), line.c_str(), static_cast<DWORD>(line.length()), &dwWritten, NULL);
+                       }
+                       FreeConsole();
+               }
+       }
 
        // Initialize temp folder
        SetupTempPath();
@@ -571,13 +584,7 @@ void CMergeApp::ApplyCommandLineConfigOptions(MergeCmdLineInfo& cmdInfo)
                        }
                        else
                        {
-                               String msg = strutils::format_string1(_T("WinMerge: Invalid key '%1' specified in /config option\n"), it.first);
-                               if (AttachConsole(static_cast<DWORD>(-1)))
-                               {
-                                       DWORD dwWritten;
-                                       WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), msg.c_str(), static_cast<DWORD>(msg.length()), &dwWritten, NULL);
-                                       FreeConsole();
-                               }
+                               cmdInfo.m_sErrorMessages.push_back(strutils::format_string1(_T("Invalid key '%1' specified in /config option"), it.first));
                        }
                }
        }
index ebc971c..1f0af46 100644 (file)
@@ -383,6 +383,10 @@ void MergeCmdLineInfo::ParseWinMergeCmdLine(const TCHAR *q)
                {
                        q = SetConfig(q);
                }
+               else
+               {
+                       m_sErrorMessages.push_back(_T("Unknown option '/") + param + _T("'"));
+               }
        }
        // If "compare file dir" make it "compare file dir\file".
        if (m_Files.GetSize() >= 2)
index 7c796ea..c476cd5 100644 (file)
@@ -88,6 +88,8 @@ public:
 
        std::map<String, String> m_Options;
 
+       std::vector<String> m_sErrorMessages;
+
 private:
 
        static const TCHAR *EatParam(const TCHAR *, String &, bool *flag = 0);