From e35ee2e8c58bf55da5f3d04915d588fb04d6809d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 7 Jan 2021 23:12:49 -0800 Subject: Report invalid command line arguments as errors Fixes wixtoolset/issues#6313 --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 6 ++---- src/WixToolset.Core/CommandLine/CommandLine.cs | 6 +++--- src/WixToolset.Core/CommandLine/CommandLineParser.cs | 8 +++++++- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index fed95958..065467bd 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -841,8 +841,7 @@ namespace WixToolset.Core.CommandLine } else { - this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); - parser.ErrorArgument = parameter; + parser.ReportErrorArgument(parameter, ErrorMessages.IllegalSuppressWarningId(paramArg)); } } @@ -859,8 +858,7 @@ namespace WixToolset.Core.CommandLine } else { - this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); - parser.ErrorArgument = parameter; + parser.ReportErrorArgument(parameter, ErrorMessages.IllegalSuppressWarningId(paramArg)); } } } diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index 5439eb39..0c21eaaa 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs @@ -97,19 +97,19 @@ namespace WixToolset.Core.CommandLine { if (!this.TryParseCommand(arg, parser, extensions, out command)) { - parser.ErrorArgument = arg; + parser.ReportErrorArgument(arg); } } else if (parser.IsSwitch(arg)) { if (!command.TryParseArgument(parser, arg) && !TryParseCommandLineArgumentWithExtension(arg, parser, extensions)) { - parser.ErrorArgument = arg; + parser.ReportErrorArgument(arg); } } else if (!TryParseCommandLineArgumentWithExtension(arg, parser, extensions) && !command.TryParseArgument(parser, arg)) { - parser.ErrorArgument = arg; + parser.ReportErrorArgument(arg); } } diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index e78da47e..015d3e62 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs @@ -12,7 +12,7 @@ namespace WixToolset.Core.CommandLine { private const string ExpectedArgument = "expected argument"; - public string ErrorArgument { get; set; } + public string ErrorArgument { get; private set; } private Queue RemainingArguments { get; } @@ -122,6 +122,12 @@ namespace WixToolset.Core.CommandLine return false; } + public void ReportErrorArgument(string argument, Message message = null) + { + this.Messaging.Write(message ?? ErrorMessages.AdditionalArgumentUnexpected(argument)); + this.ErrorArgument = argument; + } + public bool TryGetNextSwitchOrArgument(out string arg) { if (this.RemainingArguments.Count > 0) -- cgit v1.2.3-55-g6feb