From 3b61b9fc4834beb5dcff6aaa987947b4ce959b9b Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 22 Oct 2018 23:14:23 +0900 Subject: [PATCH] Write an error message to the console when unknown command-line option is specified --- Src/Merge.cpp | 21 ++++++++++++++------- Src/MergeCmdLineInfo.cpp | 4 ++++ Src/MergeCmdLineInfo.h | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Src/Merge.cpp b/Src/Merge.cpp index 9d2fc64ee..60c5814ae 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -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(-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(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(-1))) - { - DWORD dwWritten; - WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), msg.c_str(), static_cast(msg.length()), &dwWritten, NULL); - FreeConsole(); - } + cmdInfo.m_sErrorMessages.push_back(strutils::format_string1(_T("Invalid key '%1' specified in /config option"), it.first)); } } } diff --git a/Src/MergeCmdLineInfo.cpp b/Src/MergeCmdLineInfo.cpp index ebc971cd5..1f0af4615 100644 --- a/Src/MergeCmdLineInfo.cpp +++ b/Src/MergeCmdLineInfo.cpp @@ -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) diff --git a/Src/MergeCmdLineInfo.h b/Src/MergeCmdLineInfo.h index 7c796ea07..c476cd58a 100644 --- a/Src/MergeCmdLineInfo.h +++ b/Src/MergeCmdLineInfo.h @@ -88,6 +88,8 @@ public: std::map m_Options; + std::vector m_sErrorMessages; + private: static const TCHAR *EatParam(const TCHAR *, String &, bool *flag = 0); -- 2.11.0